
The developer observes that some information is not delivered at the client end. He
tries using the following code to create a reliable connection between server and
client:
public Server()
{
try
{
serverSocket = new ServerSocket(1001);
System.out.println(serverSocket.toString());
}
catch(IOException e)
{
System.out.println("Error Starting the Server . . .");
}
System.out.println("Server started . . .");
this.start();
}
The developer writes the following code for client:
public client()
{
try
{
Socket clientSocket = new Socket("192.168.0.70", 1002);
}
catch(UnknownHostException e)
{
System.err.println("Unidentified hostname");
System.exit(1);
}
}
However, the developer observes that clients are able to connect to the server only
when the server and clients exist on the same machine. But, when a client executes
on a different machine then an exception is thrown at client end. What is the cause of
this behavior of the preceding code snippet?
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.