Using the TCP Stream Driver

To use the TCP stream socket driver, you specify connection parameters for internal
buffers,
a listening port, and the maximum number of connections.

After you construct the new stream driver, you can use the socket driver for server
or
client work. For server work, the driver can monitor for connections. For client work,
the
driver can connect to a server’s endpoint address and port.

To start accepting new connections on the server, call the StartListen()
method. When new clients connect or disconnect, the socket driver sends events through
the event
bus.

During the setup for the carrier instance, call the StartListen() method for
servers and the ConnectTo() method for clients. You can do this before you assign
the m_driver member of the CarrierDesc structure.

Stream Connection Setup

To construct a stream socket driver, specify the maximum number of connections (1
for
clients), the maximum packet size, and the byte sizes for the internal buffers for
inbound and
outbound traffic.

To prepare the socket driver, use the Initialize() method with a socket
family. IPv4 and IPv6 are supported. Specify binding parameters and socket buffer
sizes. The
driver uses internal buffers to spool streamed traffic during the Update() call.
GridMate processes the Update() call when it is using the carrier
instance.

Constructing the TCP Socket Driver

The following code example shows how to construct the TCP socket driver.

Processing a Server

After you construct and initialize the stream socket driver, use the
StartListen() method to instruct the server to accept clients. The
StartListen() method takes a backlog parameter that specifies the
incoming connection request limit. The driver emits successful connections to its
event
bus.

When you are finished with the server process, but before you shut down GridMate,
call the
StopListen() method. To disconnect a client, you can use the
DisconnectFrom() method on the server’s driver instance.

Processing a Client

To connect a client to a server, create a socket driver address. To start the connection
process, use the ConnectTo() method. When the stream socket driver establishes a
connection to the server, it sends a connect event.

To disconnect from the server, the client code uses the DisconnectFrom()
method. The driver sends a disconnect event when the server gracefully disconnects
from the
client.

Sending
and Receiving Data from the Stream Driver

To send and receive data from the stream driver, you use the Send() and
Receive() methods just as you do with the UDP driver.

For both sending and receiving, the data and data size values
should be equal to or greater than the maximum packet size. If the Send() method
does not return GridMate::Driver::EC_OK, then the connection to the remote
endpoint has been closed.

The Receive() method returns the number of bytes written to the data buffer.
If it returns zero (0) bytes and returns a result code of
GridMate::Driver::EC_OK, then no more packets are ready to be read.

Javascript is disabled or is unavailable in your browser.

To use the AWS Documentation, Javascript must be enabled. Please refer to your browser's
Help pages for instructions.