Java Reference
In-Depth Information
Figure 15.2 The interface for DataServer allows the user to select a port number. It
also holds a Start button and a text area to display information on the status of the
connections with the clients.
... The run() method in class DataServer ...
/** Create a ServerSocket and loop waiting for clients. **/
public void run () {
// The server - socket is used to make connections to
// DataClients at this port number
try {
fServerSocket = new ServerSocket (fDataServerPort);
}
catch (IOException e) {
println ("Error in server socket");
return;
}
println ("Waiting for users...");
// Loop here to grab clients
while (fKeepServing) {
try {
// accept() blocks until a connection is made
Socket socket = fServerSocket.accept ();
 
Search WWH ::




Custom Search