Setting
up a UDP communication link
Introduction
User Datagram Protocol is generally
used for applications that do not require ordered reliable streams of data.
Like TCP, UDP allows an application to contact a service on a certain port
on the remote machine. However it is an unreliable and connectionless protocol.
Data is exchanged in discrete units called datagrams. 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
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 send()
; and received by using receive().
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 at the most 5 clients and sends a reply to all the clients.
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 send() and receive() can be used to communicate with the server.
Performance
monnitoring methods are also available with this class.
Usage
1.To run the server
newserver
2.To
run a client
newclient <server-address>
Output
The server echoes back to the client and sends performance data once the
send-receive is complete. Look out for the message
"HOWDY
CLIENT# 0 Total CLIENTS: 1 MESSAGE: 1"
When more than one client is connected to the server, the server accepts
messages from each client and echoes a message back.
for more information: Post your questions
online on the Quanta forum
page.