Google Search

Sunday, October 30, 2011

DATAGRAM SERVER FOR RECEIVING PACKET FROM CLIENT


DATAGRAM SERVER FOR RECEIVING PACKET FROM CLIENT


THEORY:

DatagramPacket defines several constructors. Four are described here.The first constructor specifies a buffer that will receive data,and the size of a packet.It is used
 Receibing data over a for DatagramSocket.The second form allows you to specify
An offset onto the buffer at which data will be stored.The third form specifies a target address and port,which are used by a DatagramSocket to determine where the data in
The packet will be sent.The fourth form transmit packets beginning at the specified
Offset into the data.Think of the first two forms as building an”in box”,and the second two forms as stuffing and addressing an envelope.Here are the four constructors:

           DatagramPacket(byte data[],int size)
           DatagramPacket(byte data[],int offset,int size)
           DatagramPacket(byte data[],int size,InetAddress,int port)
           DatagramPacket(byte data[],int offset,int size,InetAddress,int port)


ALGORITHM:



Single Threaded Echo Server using UDP
(Client Algorithm)


1. Create a UDPclient class
2. Declare DatagramSocket and DatagramPacket
3. Enter some string.
4. Convert the string in byte format
5. Create a DatagramPacket
6. Send the packet using DatagramSocket
7. Create another DatagramPacket which will receive the bytes from the server
8. Receive the bytes using DatagramSocket
9. Display it in the output
10. End
Single Threaded Echo Server using UDP
(Server Algorithm)

1. Create a UDPserver class
2. Declare DatagramSocket and DatagramPacket
3. Create the DatagramSocket
4. Receive the bytes using DatagramSocket
5. Display it in the output
6. Send the packet using DatagramSocket
7. End

0 comments:

Post a Comment