QUANTAnet_iovec_c: TCP Demo program


Introduction

           A message passing interface was implemented using the scatter - gather mechanisms. The interface allows transfer of non-contiguous buffers in memory over the network, using native data structures of operating systems. This eliminates the redundant memory copies which are normally involved in such transfers. The API works with both TCP and UDP data streams.

QUANTA provides users direct control of lower level tcp socket calls.

QUANTA classes used


    QUANTAnet_tcpServer_c

                A server can be set up using this class. The read/write buffer size can be varied using the setSockOptions()method. If this mehod is not called the read/write buffer sizes are set to the default value. The setSockOptions() has to be called before the init method. The port number on which the server is to be opened is given to the init() method. After this we can use the checkForNewConnections() or waitForNewConnection method to look for incoming client connections.

    QUANTAnet_tcpClient_c

                A client can be created using this class. The read/write buffer size can be varied using the setSockOptions() method. If this mehod is not called the read/write buffer sizes are set to the default value. The setSockOptions() has to be called before the connectToServer() method. It can connect to the server set up using QUANTAnet_tcpServer_c class using connectToServer(). The clients can carry out readv() and writev() operations in the blocking or non blocking mode. If the non blocking mode is being used the isReady(), isReadyToRead(), isReadyToWrite() methods may be useful. You can also change the timeout values for the blocking mode by using setTimeOut() .
                Performance measuring methods are also available and the showStats() method should be typically executed after a read/write is done over a network.

    QUANTAnet_iovec_c

The ioservertcp.cxx program in the demo sets up a TCP server and the ioclienttcp.cxx program runs a client which connects to the server. The server creates two objects of QUANTAnet_iovec_c sr_send_iovec and sr_recv_iovec which has 2 and 4 iovec structures to send and read data respectively from the clients. Similarly, the client creates two objects of QUANTAnet_iovec_c cl_send_iovec and cl_recv_iovec which has 4 and 2 iovec structures to send and read data respectively to the server.Both the server and the client use the add method to data to the iovec structures.


Usage

 1. To run the server
          ioservertcp

 2. To run a client
          ioclienttcp <server-address>

Output

On the server side:

>>> Client 0 connected>>> 10.0.0.81,6544
testing >>>>>

Data received from Client# 0
mesg1: 1
mesg1: 2
mesg1: 3
mesg1: 4
mesg1: 5

mesg2: 1.100000
mesg2: 2.200000
mesg2: 3.300000
mesg2: 4.400000
mesg2: 5.500000

mesg3: 1.100000
mesg3: 2.200000
mesg3: 3.300000
mesg3: 4.400000
mesg3: 5.500000

mesg4: cavern

On the client side:

Client IP 10.0.0.82, Port: 34665
testing >>>>>

Sent data to Server

Message from server >>>>>> Server Alive >>>>>


for more information: Post your questions online on the Quanta forum page.