TcpSocket

The TcpSocket class represents a TCP socket that allows connecting to a server, sending, and receiving data. It inherits from the Socket class, with specific methods to initialize the socket (init), establish a connection (connect), send data (send), and receive data (receive). It handles errors by throwing exceptions in case of network operation failures and uses a singleton to store the active TCP socket.

FunctionsDescription
initCreate a TCP socket using socket() and save it in the singleton. Throw an exception in case of creation failure.
connectTry to connect to the TCP server using connect(). Throw an exception if the connection fails.
sendSend a message through the TCP socket using send(). Throw an exception if the sending fails.
receiveReceive a message through the TCP socket using recv(), then return a SmartBuffer containing the received data. Throw an exception if the reception fails.