Socket client

Provides low-level streaming and encryption utilities for file upload sockets within the Norman platform.

The SocketClient handles encrypted binary streaming between the client and a Norman-managed upload socket. It is typically used by FilePush to send large assets or model files over an allocated WebSocket or TCP socket.

write(socket_info, file_stream) async staticmethod

Coroutine

Write a stream of encrypted binary data to a paired socket.

This method encrypts and transmits a binary stream to a socket endpoint using ChaCha20 encryption and flow-controlled async writes.

Parameters
  • socket_info (SocketPairingResponse) — The socket pairing information returned from FilePush.

SocketPairingResponse
  • host (str) — Target socket hostname.

  • port (int) — Socket port number.

  • encryption_key (str) — Base64-encoded ChaCha20 encryption key.

  • nonce (str) — Base64-encoded nonce used for encryption.

  • authentication_header (str) — Base64-encoded header prepended to the stream.

  • file_stream (AsyncGenerator[bytes, None]) — Asynchronous generator yielding raw binary chunks to be written.

Response Structure
  • response (AsyncGenerator[bytes, None]) — Asynchronous generator that yields the original unencrypted chunks after successful socket transmission.

Example Usage:
async def file_gen():
    async for chunk in AsyncBufferedReader(open("file.bin", "rb")):
        yield chunk

async for sent_chunk in SocketClient.write(socket_info, file_gen()):
    print(f"Sent {len(sent_chunk)} bytes...")


write_and_digest(socket_info, asset_stream) async staticmethod

Coroutine

Write an asset stream to a paired socket while computing its hash digest.

This method sends a binary stream (e.g., a model asset or input file) through an encrypted socket, and simultaneously computes its XXH3-64 checksum for validation.

Parameters
  • socket_info (SocketPairingResponse) — The socket pairing information returned from the FilePush API. Contains authentication headers, encryption keys, and socket details.

SocketPairingResponse:
  • host (str) — Target socket hostname.

  • port (int) — Socket port number.

  • encryption_key (str) — Base64-encoded encryption key.

  • nonce (str) — Base64-encoded nonce used for ChaCha20 encryption.

  • authentication_header (str) — Base64-encoded header for request authentication.

  • asset_stream (AsyncBufferedReader) — Asynchronous stream reader providing the file or asset data to be uploaded.

Response Structure
  • response (str) — Hexadecimal XXH3-64 hash digest of the uploaded file, used for checksum validation.

Example Usage:
async with AsyncBufferedReader(open("weights.pt", "rb")) as stream:
    checksum = await SocketClient.write_and_digest(socket_info, stream)
    print("Asset checksum:", checksum)

·

©

2026

·

©

2026

·

©

2026

·

©

2026