All About Class DatagramSocket in Java



DatagramSocket class represents a socket for sending and receiving datagram packets.A datagram socket is the sending or receiving point for a connection less packet delivery service.Each packet sent or received on a datagram socket is individually addressed and routed.Multiple packets sent from a machine to another may be routed differently anmd may arrive in any order.

The class DatagramSocket is given as:

public class java.net.DatagramSocket extends java.lang.Object{
//constructors
public DatagramSocket();
//constructs a DatagramSocket and binds it to any available port on the loaclhost machine
//It may throw SocketException if the socket could not be opened or the socket could not be
//bind to the specified local port.This is used to make communication between two ports in the local machines
public DatagramSocket(int port);
//constructs a DatagramSocket and binds it to any available specified port on the loaclhost machine
//It may throw SocketException if the socket could not be opened or the socket could not be
//bind to the specified local port.This constructor is used to communicate between two non localized ports
//Methods:
public synchronized void close();//To close the datagram socket that is established when the communication 
//is completed
protected void finalize();
public int getLocalPort();
public synchronized void receive(DatagramPacket pck);//takes the  Datagram packet object as a recipient 
//for datagram to be received.
public void send(DatagramPacket pck);//Takes a Datagram packet object and send the datagram's data to the previously
//defined host and port address.
}
 
All About Class DatagramSocket in Java All About Class DatagramSocket in Java Reviewed by Animesh Chatterjee on October 08, 2018 Rating: 5

No comments:

Powered by Blogger.