Skip to content

Socket

veltix.socket_core.core.SocketCore

Bases: Enum

Available socket implementations.

veltix.socket_core.base_socket.BaseSocket

Bases: ABC

Abstract base class for a single TCP connection.

Defines only the transport surface every connection shares: raw send, recv, timeout, and close. Both the backends (ThreadingSocket, AsyncSocket) and the per-connection objects they accept (AcceptedSocket) derive from it, so a connection never has to implement listener or peer lifecycle it has no use for.

Attributes:

Name Type Description
handshake_timeout float

Timeout in seconds for the handshake phase.

bus VeltixBus

Event bus for structured observability.

request_handler Any

Wired after construction on the client side.

send

send(data: bytes) -> bool

Send raw bytes over the connection.

Parameters:

Name Type Description Default
data bytes

The bytes to send.

required

Returns:

Type Description
bool

True if the data was sent successfully, False otherwise.

recv

recv(buf_size: int) -> bytes

Receive data from the connection.

Parameters:

Name Type Description Default
buf_size int

Maximum number of bytes to receive.

required

Returns:

Type Description
bytes

The received bytes, or an empty byte-string when the peer has

bytes

closed the connection (EOF).

Raises:

Type Description
OSError

On socket errors, including ConnectionResetError and BrokenPipeError. A TimeoutError is raised when a timeout is set and no data arrives in time.

settimeout

settimeout(timeout: float) -> bool

Set the socket timeout for blocking operations.

Parameters:

Name Type Description Default
timeout float

Timeout in seconds.

required

Returns:

Type Description
bool

True if the timeout was set successfully, False otherwise.

fileno

fileno() -> int

Return the underlying socket file descriptor.

Returns:

Type Description
int

The file descriptor of the underlying socket.

close abstractmethod

close() -> bool

Close the socket and release associated resources.

Returns:

Type Description
bool

True if the socket was closed successfully, False otherwise.

veltix.socket_core.threading_socket.ThreadingSocket

Bases: ServerSocket

Threading-based socket implementation for Veltix (one thread per client).

threads property

threads: dict[int, Thread]

Return the live per-client receive threads, keyed by thread id.

veltix.socket_core.async_socket.AsyncSocket

Bases: ServerSocket

Selector-based socket implementation for Veltix.

send

send(data: bytes) -> bool

Send raw bytes, queueing any remainder past the kernel buffer.

Parameters:

Name Type Description Default
data bytes

The bytes to send.

required

Returns:

Type Description
bool

True when the data was sent or queued for delivery, False on a

bool

hard connection error.