What is an InetAddress? The InetAddress is Java’s representation of an IP address. Instances of this class are used together with UDP DatagramSockets and normal Socket’s and ServerSocket’s.
What are the purposes of using InetAddress class? InetAddress class provides methods to get the IP of any host name for example www.javatpoint.com, www.google.com, www.facebook.com, etc. An IP address is represented by 32-bit or 128-bit unsigned number. An instance of InetAddress represents the IP address with its corresponding host name.
What is Datagramsocket explain in detail with example? A datagram socket is the sending or receiving point for a packet delivery service. Each packet sent or received on a datagram socket is individually addressed and routed. Multiple packets sent from one machine to another may be routed differently, and may arrive in any order.
Which of the following method returns the InetAddress associated with the socket object?
|Modifier and Type
|Method and Description
|getChannel() Returns the unique SocketChannel object associated with this socket, if any.
|getInetAddress() Returns the address to which the socket is connected.
|getInputStream() Returns an input stream for this socket.