Sender¶
veltix.network.sender.Sender
¶
Sends messages over TCP in CLIENT or SERVER mode.
CLIENT: single server connection. SERVER: sends to individual clients or broadcasts.
__init__
¶
Initialize the sender with a mode and an optional connection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mode
|
Union[Mode, str]
|
CLIENT or SERVER mode. |
required |
conn
|
Optional[BaseSocket]
|
Connection socket (required in CLIENT mode). |
None
|
Raises:
| Type | Description |
|---|---|
SenderError
|
If mode is CLIENT without a connection. |
send
¶
Send a request over the network.
In CLIENT mode, uses the internal connection. In SERVER mode, uses the provided client socket.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Request
|
Request to send. |
required |
client
|
Optional[BaseSocket]
|
Target client socket (required in SERVER mode). |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
True if the send succeeded, False otherwise. |
broadcast
¶
broadcast(
data: Request,
list_of_client: list[BaseSocket],
except_clients: Optional[list[BaseSocket]] = None,
) -> bool
Send a request to multiple clients (SERVER mode only).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Request
|
Request to broadcast. |
required |
list_of_client
|
list[BaseSocket]
|
List of target client sockets. |
required |
except_clients
|
Optional[list[BaseSocket]]
|
Optional list of clients to exclude. |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
True if all sends succeeded, False otherwise. |