Each DClient manages a single TCP connection. It sends and receives data, and can connect to servers. DClient takes a DEngine in its constructor, which dispatches the DClient's events. DClient is an abstract class, and should be inherited by a child class that implements its event handlers. See the SimpleClient sample program for an example.
The default constructor, used when the DClient will be connecting to a server. engine is a pointer to the DEngine that will handle our events.
Same as above, but allows us to set the size of the DClient's send and receive buffers to bufferSize bytes. Larger buffer sizes can result in better efficiency. The default size is 16 kilobytes, which is already quite large for most networks.
This constructor should be used in DServer's connectHandler function. newSocket is a connection that was accepted by the DServer, and will be used by the created DClient.
Same as above, but allows us to set the size of the DClient's send and receive buffers to bufferSize bytes. Larger buffer sizes can result in better efficiency. The default size is 16 kilobytes, which is already quite large for most networks.
Closes the DClient's socket. Returns false on errors and sets errMsg. closeSocket is automatically called by the destructor.
Returns the size of the send and receive buffers in bytes.
Returns a description of the most recent error.
Returns this DClient's local address. Returns an empty string if an error occurred, and sets errMsg with a description of the problem.
Returns the address of the host this DClient is connected to. Returns an empty string if an error occurred, and sets errMsg with a description of the problem.
Sends theData to the remote host. sendHandler is called when all data is sent.
Enables or disables Nagle's algorithm. By default, Nagle's algorithm is active. If many small pieces of data are sent in a short time period, they're bundled together and sent in the same TCP packet. This improves efficiency, as each TCP packet has an overhead of 40 bytes or more. Nagle's algorithm increases latency as the data isn't sent immediately, but is buffered in case it can be combined with another message.
If newValue is false, then Nagle's Algorithm will be disabled, and the send function will send the data immediately. setDelay returns false if it couldn't change the socket settings, and sets errMsg.
Causes the DClient to connect to the server at the specified hostName, which can be an IP address or domain name. portNumber is the TCP port the server is listening on. connectHandler will be called when the connection either fails or completes.
Returns the number of bytes remaining to be sent.
An event handler that's called when the DClient connects to a host, or the connection attempt fails. status is set to one of the following values from the NetworkCode enumeration:
If the connection failed, errorDesc will be set to a description of the problem.
An event handler that's called in response to a socket error, indicating that the connection is no longer valid and the socket should be closed. errorDesc contains a description of the problem.
An event handler called when data is received from the network. receivedBytes contains the data.
This event handler is called when the DClient has sent all data.