Abstract Class DatagramSocketImpl in Java

0
42
digitization, transformation, binary
Spread the love

Abstract Class DatagramSocketImpl in Java

DatagramSocketImpl is an abstract class that defines the methods necessary to implement communication through datagram and multicast sockets.

System programmers may create subclasses of this class when they need to implement datagram or multicast sockets in a nonstandard network environment, such as behind a firewall or on a network that uses a nonstandard transport protocol.

The DatagramSocketImpl class is an abstract class that defines the bulk of the methods that make the DatagramSocket and MulticastSocket classes work. Non-public subclasses of DatagramSocketImpl provide platform-specific implementations of datagram socket communication.

Normal applications never need to use or subclass this class.

The structure of the class DatagramSocketImpl is given by

public abstract class java.net.DatagramSocketImpl extends java.lang.Object {
// Default Constructor: public DatagramSocketImpl()
// Protected Instance Variables
protected FileDescriptor fd;
protected int localPort;
// Protected Instance Methods
protected abstract void bind(int lport, InetAddress laddr) throws SocketException;
protected abstract void close();
protected abstract void create() throws SocketException;
protected FileDescriptor getFileDescriptor();
protected int getLocalPort();
protected abstract byte getTTL() throws IOException;
protected abstract void join(InetAddress inetaddr) throws IOException;
protected abstract void leave(InetAddress inetaddr) throws IOException;
protected abstract int peek(InetAddress i) throws IOException;
protected abstract void receive(DatagramPacket p) throws IOException;
protected abstract void send(DatagramPacket p) throws IOException;
protected abstract void setTTL(byte ttl) throws IOException;
}

The details of the class structure are given as follows:

protected FileDescriptor fd;

protected FileDescriptor fd is the file descriptor that represents this socket.

protected int localPort;

protected int localPort is the local port number of this socket.

protected abstract void bind(int lport, InetAddress laddr);

protected abstract void bind(int lport, InetAddress laddr) method binds the socket to the given address and port. If the address or the port is unavailable, an exception is thrown.

READ  Assertion Concept Simplified In Java

Parameter
lport – A port number.
laddr – A local address.

protected abstract void close();

protected abstract void close() method closes the socket, releasing any system resources it holds.

protected abstract void create();

protected abstract void create() method creates a socket that is not bound to an address and port.

protected FileDescriptor getFileDescriptor();

protected FileDescriptor getFileDescriptor() method returns the file descriptor associated with this DatagramSocketImpl.

This method returns the file descriptor for this socket.

protected int getLocalPort();

protected int getLocalPort() method returns the local port to which this DatagramSocketImpl is bound.

This method returns the port number for this socket.

protected abstract byte getTTL();

protected abstract byte getTTL() method returns the TTL value for this socket. This value is the number of hops that an outgoing packet can traverse before it is discarded.

This method returns the time-to-live (TTL) value for this socket.

protected abstract void join(InetAddress inetaddr);

protected abstract void join(InetAddress inetaddr) method is used by MulticastSocket to join a multicast group. An exception is thrown if the given address is not a multicast address. While the socket is part of a group, it receives all packets that are sent to the group.

Parameter
inetaddr – The IP address of the group to join.

protected abstract void leave(InetAddress inetaddr);

protected abstract void leave(InetAddress inetaddr) method is used by MulticastSocket to leave a multicast group. An exception is thrown if the given address is not a multicast address.

Parameter
inetaddr – The IP address of the group to leave.

protected abstract int peek(InetAddress i);

protected abstract int peek(InetAddress i) method places the address of the next incoming packet in the given InetAddress object. The method also returns the port number of the next incoming packet. The method looks at the address of an incoming packet to determine if it should be accepted.

READ  Abstract Interface DataOutput in Java

This method returns the port number of the next incoming packet.

Parameter
i – A reference to an InetAddress object.

protected abstract void receive(DatagramPacket p);

protected abstract void receive(DatagramPacket p) method receives a datagram packet on this socket. After this method returns, the given DatagramPacket contains the packet’s data and length, and the sender’s address and port number. If the data that was sent is longer that the given packet’s data buffer, the data is truncated.

Parameter
p – The DatagramPacket that receives incoming data.

protected abstract void send(DatagramPacket p);

protected abstract void send(DatagramPacket p) method sends a packet from this socket. The packet data, packet length, destination address, and destination port number are specified by the given DatagramPacket.

Parameter
p – The DatagramPacket to be sent.

protected abstract void setTTL(byte ttl);

protected abstract void setTTL(byte ttl) method is used to set the TTL value of the socket. The TTL value is the number of hops that an outgoing packet can traverse before it is discarded.

Parameter
ttl – The new TTL value for this socket.

Apart from these DatagramSocketImpl class also has inherited methods from class- Object. They are as follows:

  • clone()
  • finalize()
  • hashCode()
  • notifyAll()
  • wait()
  • wait(long, int)
  • equals(Object)
  • getClass()
  • notify()
  • toString()
  • wait(long)


Spread the love
I am the founder and owner of the blog - TechTravelHub.com, always love to share knowledge on test automation,tools,techniques and tips.I am a passionate coder of Java and VBScript.I also publish articles on Travel ideas and great honeymoon destinations.Apart from these, I am a gear-head,love to drive across India. I have shared lots of articles here on How to travel several parts of India.Customization of cars aka car modification is my another hobby.Get in touch with me on ani01104@gamil.com

LEAVE A REPLY

Please enter your comment!
Please enter your name here