ryu_ldn::network::TcpClient
ryu_ldn::network::TcpClient
Section titled “ryu_ldn::network::TcpClient”High-level TCP client for RyuLdn protocol.
Combinestransport with protocol encoding/decoding and packet buffering for stream reassembly.LifecycleCreateinstanceCallto establish connectionSend/receive messages using send_* and receive_packet methodsCallwhen doneclassryu__ldn_1_1network_1_1TcpClient_1ReconnectionAfter disconnection (intentional or due to error), callagain to re-establish connection. Previous session state is NOT preserved - send Initialize again after reconnecting.classryu__ldn_1_1network_1_1TcpClient_1
Members
Section titled “Members”m_socket
Section titled “m_socket”Type: Socket
Underlying TCP socket.
m_recv_buffer
Section titled “m_recv_buffer”Type: < 0x2000 >
Buffer for TCP stream reassembly (8KB - saves 56KB!)
m_send_buffer
Section titled “m_send_buffer”Type: uint8_t
Buffer for encoding outgoing packets.
Methods
Section titled “Methods”TcpClient
Section titled “TcpClient”void TcpClient()Default constructor.
Default constructor - creates disconnected client.Creates a disconnected client. Callto establish connection.Initializes internal buffers. No connection is established.
~TcpClient
Section titled “~TcpClient”void ~TcpClient()Destructor.
Destructor - ensures clean disconnection.Automatically disconnects if connected.
TcpClient
Section titled “TcpClient”void TcpClient(const&)Parameters:
param(const&)
operator=
Section titled “operator=”& operator=(const&)Parameters:
param(const&)
Returns: &
TcpClient
Section titled “TcpClient”void TcpClient(&& other)Move constructor.
Transfers ownership of socket and buffers from other client.otherClient to move fromparam
Parameters:
other(&&)
operator=
Section titled “operator=”& operator=(&& other)Move assignment operator.
Disconnects current connection (if any) and takes ownership from other.otherClient to move fromparamReference to this clientreturn
Parameters:
other(&&)
Returns: &
connect
Section titled “connect”ClientResult connect(const char * host, uint16_t port, uint32_t timeout_ms)Connect to RyuLdn server.
Establishes TCP connection to the specified server. After successful connection, the client is ready to send/receive protocol messages.Establishes TCP connection and prepares for protocol communication. The receive buffer is reset to ensure clean state.
Parameters:
host(const char *)port(uint16_t)timeout_ms(uint32_t)
Returns: ClientResult
disconnect
Section titled “disconnect”void disconnect()Disconnect from server.
Closes the connection and resets internal state. Safe to call even if not connected (no-op in that case).Closes socket and resets internal state.
is_connected
Section titled “is_connected”bool is_connected()Check if client is connected.
Check connection status.true if TCP connection is establishedreturnfalse if disconnected or connection was lostreturnThis only checks local state. The server may have closed the connection; this will be detected on next send/receive.note
Returns: bool
send_packet
Section titled “send_packet”ClientResult send_packet(protocol::PacketId type, const void * payload, size_t payload_size)Send a raw protocol packet.
Low-level send function for any packet type. The packet is encoded with the protocol header and sent over the socket.Encodes the packet with header and sends over the socket. Uses internal send buffer for encoding.
Parameters:
type(protocol::PacketId)payload(const void *)payload_size(size_t)
Returns: ClientResult
send_raw
Section titled “send_raw”ClientResult send_raw(const void * data, size_t size)Send raw pre-encoded data.
Sends data that has already been encoded with protocol header. Used by P2P components to forward notifications.dataPre-encoded packet datasizeSize of data in bytesparamif sentreturnif not connectedreturnif send failedreturn
Parameters:
data(const void *)size(size_t)
Returns: ClientResult
send_initialize
Section titled “send_initialize”ClientResult send_initialize(const protocol::InitializeMessage & msg)Send Initialize message.
First message to send after connecting. Identifies the client to the server with session ID and MAC address.msgInitialize message with client ID and MACparamClientResult indicating success or errorreturnSend with zeros for id/mac to request new session from servernote
Parameters:
msg(const protocol::InitializeMessage &)
Returns: ClientResult
send_passphrase
Section titled “send_passphrase”ClientResult send_passphrase(const protocol::PassphraseMessage & msg)Send Passphrase message.
Sent when joining a private (password-protected) room.msgPassphrase message with room passwordparamClientResult indicating success or errorreturn
Parameters:
msg(const protocol::PassphraseMessage &)
Returns: ClientResult
send_passphrase
Section titled “send_passphrase”ClientResult send_passphrase(const char * passphrase)Send Passphrase message.
Send Passphrase message (string convenience overload)Sends passphrase for room filtering. Must be sent after TCP connection and before Initialize packet.passphrasePassphrase string (null-terminated)paramClientResult indicating success or errorreturn
Parameters:
passphrase(const char *)
Returns: ClientResult
send_ping
Section titled “send_ping”ClientResult send_ping(const protocol::PingMessage & msg)Send Ping message.
Keepalive message for connection health check.msgPing message with requester and idparamClientResult indicating success or errorreturnServer will echo back the ping when requester=0note
Parameters:
msg(const protocol::PingMessage &)
Returns: ClientResult
send_disconnect
Section titled “send_disconnect”ClientResult send_disconnect(const protocol::DisconnectMessage & msg)Send Disconnect message.
Notifies server that client is leaving the session gracefully.msgDisconnect message with reason codeparamClientResult indicating success or errorreturnCall this beforefor graceful shutdownnote
Parameters:
msg(const protocol::DisconnectMessage &)
Returns: ClientResult
send_create_access_point
Section titled “send_create_access_point”ClientResult send_create_access_point(const protocol::CreateAccessPointRequest & request)Send CreateAccessPoint request.
Request to create a new network session (host mode).requestAccess point configurationparamClientResult indicating success or errorreturn
Parameters:
request(const protocol::CreateAccessPointRequest &)
Returns: ClientResult
send_create_access_point_private
Section titled “send_create_access_point_private”ClientResult send_create_access_point_private(const protocol::CreateAccessPointPrivateRequest & request, const uint8_t * advertise_data, size_t advertise_size)Send CreateAccessPointPrivate request.
Request to create a new private (password-protected) network session.requestPrivate access point configurationadvertise_dataOptional advertise dataadvertise_sizeSize of advertise dataparamClientResult indicating success or errorreturn
Parameters:
request(const protocol::CreateAccessPointPrivateRequest &)advertise_data(const uint8_t *)advertise_size(size_t)
Returns: ClientResult
send_connect
Section titled “send_connect”ClientResult send_connect(const protocol::ConnectRequest & request)Send Connect request.
Request to join an existing network session.requestConnection request with target network infoparamClientResult indicating success or errorreturn
Parameters:
request(const protocol::ConnectRequest &)
Returns: ClientResult
send_connect_private
Section titled “send_connect_private”ClientResult send_connect_private(const protocol::ConnectPrivateRequest & request)Send ConnectPrivate request.
Request to join a private (password-protected) network session.requestPrivate connection requestparamClientResult indicating success or errorreturn
Parameters:
request(const protocol::ConnectPrivateRequest &)
Returns: ClientResult
send_scan
Section titled “send_scan”ClientResult send_scan(const protocol::ScanFilterFull & filter)Send Scan request.
Request to scan for available network sessions.filterScan filter criteriaparamClientResult indicating success or errorreturn
Parameters:
filter(const protocol::ScanFilterFull &)
Returns: ClientResult
send_proxy_data
Section titled “send_proxy_data”ClientResult send_proxy_data(const protocol::ProxyDataHeader & header, const uint8_t * data, size_t data_size)Send proxy data.
Send game data through the proxy to another player.Proxy data packets are special - they combine header + variable data. We need to encode them together in the send buffer.
Parameters:
header(const protocol::ProxyDataHeader &)data(const uint8_t *)data_size(size_t)
Returns: ClientResult
send_set_accept_policy
Section titled “send_set_accept_policy”ClientResult send_set_accept_policy(const protocol::SetAcceptPolicyRequest & request)Send SetAcceptPolicy request.
Host-only command to change the accept policy for new connections.requestAccept policy requestparamClientResult indicating success or errorreturn
Parameters:
request(const protocol::SetAcceptPolicyRequest &)
Returns: ClientResult
send_set_advertise_data
Section titled “send_set_advertise_data”ClientResult send_set_advertise_data(const uint8_t * data, size_t size)Send SetAdvertiseData request.
Host-only command to update the advertise data for the network.dataAdvertise data buffersizeSize of advertise data (max 384 bytes)paramClientResult indicating success or errorreturn
Parameters:
data(const uint8_t *)size(size_t)
Returns: ClientResult
send_reject
Section titled “send_reject”ClientResult send_reject(const protocol::RejectRequest & request)Send Reject request.
Host-only command to reject/kick a player from the network.requestReject request with node ID and reasonparamClientResult indicating success or errorreturn
Parameters:
request(const protocol::RejectRequest &)
Returns: ClientResult
receive_packet
Section titled “receive_packet”ClientResult receive_packet(& type, void * payload, size_t payload_buffer_size, size_t & payload_size, int32_t timeout_ms)Receive next protocol packet.
Waits for and receives the next complete protocol packet from the server. Handles TCP stream reassembly internally using PacketBuffer.This function handles the complexity of TCP stream reassembly:
Parameters:
type(&)payload(void *)payload_buffer_size(size_t)payload_size(size_t &)timeout_ms(int32_t)
Returns: ClientResult
has_packet_available
Section titled “has_packet_available”bool has_packet_available()Check if a complete packet is available.
Non-blocking check for packet availability. Use this to poll for packets without blocking.true if at least one complete packet is bufferedreturnfalse if no complete packet availablereturnCallafter this returns true to get the packetnote
Returns: bool
set_nodelay
Section titled “set_nodelay”ClientResult set_nodelay(bool enable)Enable TCP_NODELAY (disable Nagle’s algorithm)
Enable/disable TCP_NODELAY.Reduces latency for small packets at the cost of slightly higher network overhead. Recommended for gaming applications.enabletrue to disable Nagle, false to enableparamon successreturnif not connectedreturn
Parameters:
enable(bool)
Returns: ClientResult
Methods
Section titled “Methods”socket_to_client_result
Section titled “socket_to_client_result”ClientResult socket_to_client_result(SocketResult socket_result)Convert SocketResult to ClientResult.
Maps low-level socket errors to higher-level client results.Maps low-level socket errors to appropriate client-level results.
Parameters:
socket_result(SocketResult)
Returns: ClientResult
Methods
Section titled “Methods”receive_into_buffer
Section titled “receive_into_buffer”ClientResult receive_into_buffer(int32_t timeout_ms)Try to receive more data into packet buffer.
Receive data into packet buffer.Reads available data from socket into the packet buffer.Reads available data from socket and appends to the receive buffer. Handles WouldBlock gracefully for non-blocking operation.
Parameters:
timeout_ms(int32_t)
Returns: ClientResult