All About Class DatagramSocket in Java

0
14
Spread the love
  • 1
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
    1
    Share


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.
}
 
Don't miss out!
Subscribe To Newsletter

Receive top technical news, lesson ideas, travel tips and more!

Invalid email address
Give it a try. You can unsubscribe at any time.

Spread the love
  • 1
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
    1
    Share

LEAVE A REPLY

Please enter your comment!
Please enter your name here