A simple TCP server client model
has been set up in this demo and then data of various types is transmitted.
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 :
QUANTAnet_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.
A client can be created using this class. It can connect to the server set up using QUANTAnet_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() .
2. To run a client
client <server-address>
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: Post your questions online on the Quanta forum page.