CS2307 – Network Lab

Socket Programming

UDP Sockets TCP guarantees the delivery of packets and preserves their order on destination. Sometimes these features are not required, since they do not come without performance costs, it would be better to use a lighter transport protocol such as UDP (User Datagram Protocol). UDP is an unreliable protocol, i.e., it does not include software mechanisms for retrying on transmission failures or data corruption (unlike TCP), and has restrictions on message length (< 65536 bytes). Examples are NFS, DNS, SNMP, Clock Server, Ping, VoIP, online games etc. Unlike TCP there is no concept of a connection, UDP is a protocol that sends independent packets of data, called datagrams, from one computer to another with no guarantees about arrival and sequencing. No packet has any knowledge of the preceding or following packet. The recipient does not acknowledge packets, thereby the sender does not know whether the transmission was successful. The format of datagram packet is Message Length Host

Server Port

A program can use a single UDP socket to communicate with more than one host and port number, but it is convenient for most UDP client programs to maintain the fiction that there is a connection, by keeping a local record of each server host and port number. A UDP server does not have to listen for and accept client connections, and a UDP client need not connect to a server. Java supports datagram communication through the following classes: DatagramPacket DatagramSocket The DatagramPacket object is the data container, while the DatagramSocket is the mechanism used to send or receive the DatagramPackets.

http://cseannauniv.blogspot.com

Vijai Anand

UDP Sockets

TCP guarantees the delivery of packets and preserves their order on destination. Sometimes these features are not required, since they do not come without performance costs, it would be better to use a lighter transport protocol such as UDP (User Datagram. Protocol). UDP is an unreliable protocol, i.e., it does not include ...

11KB Sizes 3 Downloads 217 Views

Recommend Documents

No documents