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 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 the socket and release associated resources.
Returns:
| Type | Description |
|---|---|
bool
|
True if the socket was closed successfully, False otherwise. |
bind
abstractmethod
¶
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 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
¶
Set the socket timeout for blocking operations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timeout
|
float
|
Timeout in seconds, or |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if the timeout was set successfully, False otherwise. |
close_client
abstractmethod
¶
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 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
¶
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. |