
The developer writes the following code to establish the connection with the
available port on the host machine:
import java.net.*;
public class AddTest{
public static void main(String args[]) {
try{
DatagramSocket socket = new DatagramSocket();
if(socket.isBound())
System.out.println("Socket is bound");
if(socket.isConnected())
System.out.println("Socket is connected");
socket.close();
if(socket.isBound())
System.out.println("Socket is bound");
if(socket.isConnected())
System.out.println("Socket is connected");
}catch(Exception e){
System.out.println("Error " + e);
}
}
}
However the connection was not established. Predict the output of the preceding
code. Explain why the connection cannot be established.
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.