Java Reference
In-Depth Information
Fig. 2.7
Example output from the GetRemoteTime program
To illustrate just how easy it is to provide a server that implements the Daytime
protocol, example code for such a server is shown below. The program makes use
of class Date from package java.util to create a Date object that will automatically
hold the current day, date and time on the server's host machine. To output the date
held in the Date object, we can simply use println on the object and its toString
method will be executed implicitly (though we could specify toString explicitly, if
we wished).
import java.net.*;
import java.io.*;
import java.util.Date;
public class DaytimeServer
{
public static void main(String[] args)
{
ServerSocket server;
fi nal int DAYTIME_PORT = 13;
Socket socket;
try
{
server = new ServerSocket(DAYTIME_PORT);
do
Search WWH ::




Custom Search