Java Reference
In-Depth Information
//above stream…
theTime = input.nextLine();
//Add the host's response to the text in
//the JTextArea…
display.append("The date/time at " + host
+ " is " + theTime + "\n");
hostInput.setText("");
}
catch (UnknownHostException uhEx)
{
display.append("No such host!\n");
hostInput.setText("");
}
catch (IOException ioEx)
{
display.append(ioEx.toString() + "\n");
}
fi nally
{
try
{
if (socket!=null)
socket.close(); //Close link to host.
}
catch(IOException ioEx)
{
System.out.println(
"Unable to disconnect!");
System.exit(1);
}
}
}
}
If we run this program and enter ivy.shu.ac.uk as our host name in the client's
GUI, the result will look something like that shown in Fig. 2.7.
Unfortunately, it is rather diffi cult nowadays to fi nd a host that is running the
Daytime protocol. Even if one does fi nd such a host, it may be that the user's own
fi rewall blocks the output from the remote server. If this is the case, then the user
will be unaware of this until the connection times out—which may take some time!
The user is advised to terminate the program (with Ctrl-C) if the waiting time
appears to be excessive. One possible way round this problem is to write one's own
'daytime server'…
Search WWH ::




Custom Search