Data packing


Introduction

         The idea here is to provide a safe mechanism to pack data before it is sent out on a network and to unpack it when it is received at the other end. The datapack class automatically takes care of the little endian and big endian conversions (the library has to be compiled with the appropriate flags (CAVERN_LITTLE_ENDIAN_FORMAT or CAVERN_BIG_ENDIAN_FORMAT)
The datapack class also has array datapacking functions, which can be useful for packing an array of values and send them across the network.

A simple TCP server client model has been set up in this demo and then data of various types is transmitted.
 


CAVERNsoft classes used

    CAVERNnet_datapack_c

              An object of this class must be created whenever data is to be packed or unpacked. Use initPack() method to assign the object to a suitable memory bufferand then the various pack*() methods may be used. If you want to unpack then use the initUnpack() method before any actual unpacking to attach the object to a buffer and then use the unpack*() methods. When the size of the data buffer is being estimated, use the sizeof_*() methods. The methods is this class can pack or unpack the following types of data : float, integer, 32-bit integer, long integer, 64 bit integer, double, character or arrays of all these data types.

               The server.cxx packs certain data types and sends them to the client and the client.cxx creates a client which receives the buffer and unpacks the data and displays them. The client server model is set up using the following classes :
    CAVERNnet_tcpServer_c

                A server can be set up using this class. The port number on which the server is to be opened is given to the init() method. After this we can use the checkForNewConnections() method to look for incoming client connections.

    CAVERNnet_tcpClient_c

                A client can be created using this class. It can connect to the server set up using CAVERNnet_tcpServer_c class using connectToServer(). The clients can carry out read() and write() 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() .


Usage

 1. To run the server
          server

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

Output

   At the server:

    char=1
    int=4
    float=4
    double=8
    long=4

    Send Char: A
    Send Int: 20000000
    Send Long: 1138
    Send Float: 3.330000
    Send Double: 4.444440
    Send String: thx1138
    Send Float Array - with the floats: 1.1,    2.2,    3.3,    4.4
    SIZE: 45/45

At the client :

    Received Char: A
    Received Int: 20000000
    Received Long: 1138
    Received Float: 3.330000
    Received Double: 4.444440
    Received String: thx1138
    Received Float Array - with the floats: 1.1,    2.2,    3.3,    4.4


for more information email : cavern@evl.uic.edu