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 defining the socket backend interface.

Concrete implementations (ThreadingSocket, AsyncSocket) must implement every abstract method declared here. The server and client layers depend only on this interface, allowing socket backends to be swapped at runtime.

Attributes:

Name Type Description
client_manager ClientsManager

Manages connected client entries.

handshake_timeout float

Timeout in seconds for the handshake phase.

bus VeltixBus

Event bus for structured observability.

client_allocator Optional[ClientAllocator]

Optional ID allocator for client-bound request IDs.

send abstractmethod

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.

close abstractmethod

close() -> bool

Close the socket and release associated resources.

Returns:

Type Description
bool

True if the socket was closed successfully, False otherwise.

bind abstractmethod

bind(
    host: str,
    port: int,
    max_client: int,
    buffer_size: int,
    timeout: float,
) -> bool

Bind the socket to an address and start listening for connections.

Parameters:

Name Type Description Default
host str

The host address to bind to.

required
port int

The port number to bind to.

required
max_client int

Maximum number of concurrent clients (-1 for unlimited).

required
buffer_size int

Receive buffer size in bytes.

required
timeout float

Timeout in seconds for handshakes.

required

Returns:

Type Description
bool

True if binding succeeded, False otherwise.

connect abstractmethod

connect(
    host: str, port: int, buffer_size: int, timeout: float
) -> bool

Connect to a remote server.

Parameters:

Name Type Description Default
host str

The server host address.

required
port int

The server port number.

required
buffer_size int

Receive buffer size in bytes.

required
timeout float

Timeout in seconds for the connection attempt.

required

Returns:

Type Description
bool

True if the connection was established, False otherwise.

settimeout abstractmethod

settimeout(timeout: float) -> bool

Set the socket timeout for blocking operations.

Parameters:

Name Type Description Default
timeout float

Timeout in seconds, or None for non-blocking mode.

required

Returns:

Type Description
bool

True if the timeout was set successfully, False otherwise.

close_client abstractmethod

close_client(client: Union[ClientEntry, int]) -> bool

Close a specific client connection on the server side.

Parameters:

Name Type Description Default
client Union[ClientEntry, int]

The client entry or client ID to disconnect.

required

Returns:

Type Description
bool

True if the client was disconnected, False otherwise.

disconnect abstractmethod

disconnect(timeout: float) -> bool

Disconnect from the remote server (client-side).

Parameters:

Name Type Description Default
timeout float

Timeout in seconds for the disconnection.

required

Returns:

Type Description
bool

True if disconnection succeeded, False otherwise.

recv abstractmethod

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 on failure.

veltix.socket_core.threading_socket.ThreadingSocket

Bases: BaseSocket

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

veltix.socket_core.async_socket.AsyncSocket

Bases: BaseSocket

Selector-based socket implementation for Veltix.