Java Reference
In-Depth Information
return;
}
try (Socket socket = new Socket(args[0], 13))
{
InputStream is = socket.getInputStream();
int ch;
while ((ch = is.read()) != -1)
System.out.print((char) ch);
}
catch (UnknownHostException uhe)
{
System.err.println("unknown
host:
"+uhe.getMessage());
}
catch (IOException ioe)
{
System.err.println("I/O
error:
"+ioe.getMessage());
}
}
}
Listing 9-1 describes an application that creates a Socket instance connected to
a remote server on port 13, which is reserved for the Internet's Daytime Protocol.
According to this protocol, a client socket connects to a server process on port 13
and the process implementing Daytime immediately returns an ASCII ( ht-
tp://en.wikipedia.org/wiki/Ascii )characterstringcontainingthecurrent
date and time to the client socket.
Note TheInternetEngineeringTaskForcepublishesmemorandathatdescribemeth-
ods, behaviors, research, or innovations applicable to the working of the Internet and
Internet-connectedsystems.Thesememorandaarecollectivelyknownas Request For
Comment (RFC) documents. RFC 867 describes the Daytime Internet protocol ( ht-
tp://tools.ietf.org/html/rfc867 ) and doesn't mandate a specific syntax
for the ASCII string (its implementers are free to use their own syntax).
Various timeservers implement Daytime (e.g., the server running on the computer
associated with Internet domain name time.nist.gov ). Recognizing this fact,
Search WWH ::




Custom Search