Opening a Socket Server connection: Tutorial

This tutorial describes how an application can open and manage a connection to the Socket Server. Other Socket Server tutorials build upon this tutorial. The Socket Server is also known as ESock.

Connecting to the Socket Server

The RSocketServ class provides the Connect() function to create a session to the socket server.

Procedure

The steps to connect and then close a session with the Socket Server are:

  • Call one of the RSocketServ::Connect() functions.

  • Perform socket operations

  • Call Close to end the session with the Socket Server

Example

RSocketServ ss;

// Connect to ESOCK
ss.Connect();

// Perform operations on the socket server
...

// Close the connection
ss.Close();

Further considerations

The RSocketServ::Connect() function allows optional extra information to be sent to the Socket Server to change the performance of the connection. Two optional parameters are available:

  1. Message Slots - If the client application expects to keep a large number of requests open at the same time, then the client application can increase the message slots available to the connection.

  2. Protocol Preference - If the client application will use the connection to interact with only one protocol, then this protocol should be specified. The Socket Server uses the preferred protocol to improve the efficiency of the messages between the client application and the protocol

The RSocketServ connection allows a number of sub-connections that offer more functionality. The sub-connections available are:

The purpose of each of these sub-connections is described in the .

Procedure

The procedure to attach any of these sub-connections is:

  1. Create or use an existing RSocketServ session.

  2. Call the Open() function on the object for the sub-connection class. Pass into the Open() function a reference to the RSocketServ session.

  3. Perform sub-connection operations

  4. Call Close to end the sub-session

Example 1: Socket (RSocket)

RSocketServ ss;
RSocket sock;

// Connect to the Sockets Server
ss.Connect();

// open a socket
sock.Open(ss);

// Perform operations on the socket
...

// Close the socket connection
sock.Close();

Example 2: Connection Management (RConnection)

RSocketServ ss;
RConnection conn;

// Connect to the Sockets Server
ss.Connect();

// Open the Connection Management sub-connection
conn.Open(ss);

// Perform operations on the connection
...

// Close the sub-connection and connection
ss.Close();

This example shows that you do not need to close sub-connections explicitly. If you close the RSocketServ connection, the Comms Framework closes all attached sub-connections.

Related reference