Java Reference
In-Depth Information
fi nally
{
System.out.println(
"\n* Closing connection… *");
datagramSocket.close();
//Step 8.
}
}
}
For the preceding application to work, UDP must be installed and working on the
host machine. As for TCP/IP, if there is a working Internet connection on the
machine, then UDP is running. Once again, in order to start the application, fi rst
open two command windows and then start the server running in one window and
the client in the other. (Start the server before the client!) As before, the example
screenshots in Figs. 2.5 and 2.6 show the dialogues between the server and two
clients. Observe the differences in output between this example and the correspond-
ing TCP/IP example. (Note that the change at the client end is simply the rather
subtle one of cumulative message-numbering.)
Fig. 2.6 Example output from the UDPEchoClient program (with two clients connecting
separately)
Search WWH ::




Custom Search