QUANTAnet_iovec_c: UDP 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. The simplicity of UDP makes it a faster service than TCP. QUANTA classes can be used to establish communication using UDP.
More about UDP?

QUANTA classes used

  QUANTAnet_udp_c
                A UDP object can be created using this class. The init() method is used to open a socket and specify a port number(required if the object is a server). Data can be sent by using setSendAddress() and writev() ; and received by using readv(). By default these operations are in the blocking mode and they can be made non-blocking by setting the blockingType parameter in the send() and receive() methods or by calling the makeNonBlocking() method.

                The newserver.cxx program creates an UDP object and assigns port number 6000 as the transmitting port by calling the init() method. It receives messages from the client and sends a reply to the client. To make sure that the current client has not already been encountered a CheckClient function can be written using the clone() and copyReceiveAddressToSendAddress() methods.

                The newclient.cxx program opens a dynamic port (ie. port number is not specified for a client object in the init() method). To send data to the server the port number is specified in setSendAddress() . After this writev() and readv() can be used to communicate with the server.

             Performance monnitoring methods are also available with this class.

QUANTAnet_iovec_c

The ioserverudp.cxx program in the demo sets up a UDP server and the ioclientudp.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
                 ioserverudp

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

Output

On the server side:

Data received from Client IP:206.220.241.53 Port:33136
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

Sent data to Client. IP:206.220.241.53 Port:33136

On the client side:

Client IP 10.0.0.81, Port: 33136

Sent data to Server

Message from server >>>>>> Server Alive >>>>>
Client IP 10.0.0.81, Port: 33136


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