udp sockets java udp sockets
play

UDP Sockets Java UDP Sockets Internet Application Development - PDF document

UDP Sockets Java UDP Sockets Internet Application Development Internet Application Development T UDP stands for User Datagram Protocol . UDP provides an unreliable packet delivery system built on top of the IP send protocol. As with IP, each


  1. UDP Sockets Java UDP Sockets Internet Application Development Internet Application Development T UDP stands for User Datagram Protocol . UDP provides an unreliable packet delivery system built on top of the IP send protocol. As with IP, each packet is an individual, and is Server packet Client handled separately. packet T Because of this, the amount of data that can be sent in a receive Internet UDP packet is limited to the amount that can be contained Internet in a single IP packet (approx. 64k). send T UDP packets are stamped with client and server addresses packet and port numbers. Server receive T They can arrive out of order or not at all. No packet has UDP connections are used in a any knowledge of the preceding or following packet. The slightly different way to TCP recipient does not acknowledge packets, so the sender sockets - they act like the postal does not know that the transmission was successful. service rather than a telephone. UDP Sockets TCP versus UDP Sockets Internet Application Development Internet Application Development T Clients that have one request and one response use UDP. T The advantages of TCP is that is has high reliability , and UDP has low start-up overheads. Examples of its use allows message verification. It is used when all data that is include DNS ( Domain Name Service ) and NFS . sent must arrive. For instance it provides a reliable way to T UDP is potentially unreliable and has no notion of the send chat text and to send animation key frames. T The advantages of UDP are all based around speed -it’s a presence of undetected errors in transmission. The data integrity is guaranteed, because check summing is more simpler protocol than TCP and has less overheads. It employed, but its delivery and sequence is not. is good for things such as the efficient transmission of T UDP packets may be corrupted in transit, lost due to animation sub-frames and is generally very useful for sending information that will be updated at short intervals - congestion in a router, or lost due to buffer overrun in the such as video and audio. receiver's buffer. T TCP is probably a better choice for communication between T In all cases their is no indication given to the sending networks under high traffic conditions. UDP, on the other process - in other words - packets can just disappear !! hand, is broadcast-capable and provides high performance. TCP versus UDP Sockets TCP versus UDP Sockets Internet Application Development Internet Application Development T When applications developers create programs for T One more major difference between TCP and UDP sockets TCP/UDP/IP networks, they can choose TCP or UDP at the is the way they transfer data. transport layer. T In fact, they are fundamentally different in their data T The main difference (as far as this module is concerned) is model. TCP is stream-based (as we have seen in the tutorials) and UDP is datagram-based . that TCP provides reliability control services, while UDP trades off those services to improve performance. T This means that with UDP, if data is lost or delivered out of T Most applications use TCP because reliability is crucial. For order, it happens with datagram granularity. example, FTP uses TCP to ensure that an exact copy of a T Since TCP is stream based, it does not honour your file is delivered to the recipient. Multimedia applications use message boundaries. TCP rides on top of IP, which is UDP because they can tolerate some loss. datagram based, so there is, in fact, packetizing happening T Actually, multimedia applications often run RTP (Real- when TCP data is sent, but TCP is at liberty to split your time Transport Protocol) on top of UDP. RTP is a service send() up into several actual packets or to coalesce several for controlling the transmission rate of multimedia. send() operations into one packet. 1

  2. Java UDP Sockets A Java UDP Client Internet Application Development Internet Application Development T So far all the Java sockets code we have looked at has The steps for implementing a UDP client in Java are :- been for TCP/IP (connection oriented) sockets. T Java, as you might expect, does indeed have support //1) Create an “empty” Datagram Socket for UDP/ I P ( User Datagram Packet ) sockets . DatagramSocket socket = new DatagramSocket(); T In fact, these are the only protocols that sit directly on //2) Create a Datagram Packet with server information IP that Java supports - there is no support for ICMP* DatagramPacket packet = new DatagramPacket(byte[] buf, int len, addr, 1026); (used for ping) for instance. Nor does Java support raw IP packet transmission. //3) send data to server socket.send(packet); T The two classes java.net.DatagramSocket and //4) get some data from server java.net.DatagramPacket are used to implement packet = new DatagramPacket(buf, buf.length); UDP sockets transmissions using Java. Note that there is socket.receive(packet); no such thing as a UDP server class. *Internet message control protocol A Java UDP Server UDP for real time multimedia Internet Application Development Internet Application Development T The primary objective of UDP is to deliver packets on time. //1) Create a Datagram Socket with a specific port DatagramSocket socket = new DatagramSocket(1026); T At the same time, some amount of packet drop is //2) Prepare an “empty” Datagram Packet acceptable. A single dropped packet in a video stream DatagramPacket packet = may not be detectable to a viewer, but attempting to new DatagramPacket(byte[] buf, int len); recover the packet may cause delays that are detectable. //3) Receive “request” data from a client T Streamed applications often provide some form of flow socket.receive(packet); control on their own. If a video application notices that //4) get client info packets are being dropped, it may dynamically increase InetAddress address = packet.getAddress(); the compression ratio or drop packets in a controlled way int port = packet.getPort(); to match available bandwidth on the network, while still //5) Send some data to the client providing quality that it considers reasonable. packet = new DatagramPacket(buf, buf.length, T It cannot rely on UDP for this, and using TCP for flow and address, port); socket.send(packet); congestion control would be inefficient. Real Time Protocol RTP UDP for real time multimedia Internet Application Development Internet Application Development T In fact, most real-time applications have their own special T The Real Time Protocol (RTP) is an established, flow-control requirements that the generic control standardised, protocol that provides end-to-end network provided by IP/UDP/TCP cannot provide. transport functions for transporting real-time data such as audio and video. T UDP-based real-time applications must be self-regulating - T RTP provides payload type identification, sequence in other words, the responsibility for the effectiveness will migrate up to the application layer. numbering and time stamping. RTP allows for packets to be transported out of order and reassembled in T Keep in mind that real-time applications that use UDP will correct order at the receiving end. still attempt to grab network bandwidth, possibly causing congestion in the network. While real-time applications T It relies on the underlying protocols to provide delivery may be able to control the flow between end systems, of RTP data and RTCP control data. they do nothing to prevent flows from congesting the T Audio and Video are transmitted as separate RTP network. That is a traffic management issue, and probably sessions, which gives the user the advantage of outside the scope of this module. receiving either of the media if so required. 2

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend