raisin::tcp_viewer::TcpClient
class · #include <rayrai/RaisimTcpCommon.hpp>
Cross-platform TCP client for the Rayrai/RaisimServer protocol.
The client owns platform socket setup, including Winsock startup on Windows. Messages are length-prefixed frames shared with raisim::RaisimServer.
Public types
IoStatus
enum class IoStatusStatus for the last I/O operation.
| Enumerator | Description |
|---|---|
Ok | The operation completed. |
WouldBlock | Non-blocking I/O made no or partial progress; retry later. |
Error | The operation failed; see lastError(). |
Constructors & destructor
~TcpClient
~TcpClient()Public member functions
connectTo
bool connectTo(
const std::string &host,
int port,
bool verbose=true,
int timeoutMs=0)Connect to a server host/port.
Parameters
| Parameter | Description |
|---|---|
host | Hostname or IP. |
port | TCP port. |
verbose | True to log connection errors. |
timeoutMs | Connection timeout in milliseconds; 0 or negative performs a blocking connect. |
Returns True if connection succeeded.
disconnect
void disconnect()Disconnect and reset internal state.
isConnected
bool isConnected() constCheck connection state.
Returns True if connected.
peerIsLoopback
bool peerIsLoopback() constWhether the connected server runs on this computer, judged by the address the socket is connected to (127.0.0.0/8, ::1 or an IPv4-mapped 127.x.y.z), not by the host name, which may resolve anywhere.
Returns False when not connected.
sendMessage
bool sendMessage(const std::vector<char> &payload)Send a length-prefixed message payload.
Prepends the int32 total frame size. Fails for an empty payload; a payload that would exceed kMaxMessageBytes fails and marks the client disconnected.
Parameters
| Parameter | Description |
|---|---|
payload | Raw payload bytes. |
Returns True on success.
recvMessage
bool recvMessage(std::vector<char> &payload)Receive a length-prefixed message payload.
Parameters
| Parameter | Description |
|---|---|
payload | Output payload bytes. |
Returns True only when a complete payload has been received. Returns false while a non-blocking receive is incomplete; use lastIoWouldBlock() and consumeRecvProgress() to distinguish that state from an error.
lastIoWouldBlock
bool lastIoWouldBlock() constCheck if the last I/O would have blocked.
Returns True if would-block was encountered.
consumeRecvProgress
bool consumeRecvProgress()Consume the internal receive-progress flag.
Returns True if there was progress since last call.
lastError
std::string lastError() constGet the last error string.
Returns Error message string.