www.pudn.com > jnp-src.rar > ChatServer.java
/*
* Java Network Programming, Second Edition
* Merlin Hughes, Michael Shoffner, Derek Hamner
* Manning Publications Company; ISBN 188477749X
*
* http://nitric.com/jnp/
*
* Copyright (c) 1997-1999 Merlin Hughes, Michael Shoffner, Derek Hamner;
* all rights reserved; see license.txt for details.
*/
import java.io.*;
import java.net.*;
import java.util.*;
public class ChatServer {
public static void main (String args[]) throws IOException {
if (args.length != 1)
throw new IllegalArgumentException ("Syntax: ChatServer ");
int port = Integer.parseInt (args[0]);
ServerSocket server = new ServerSocket (port);
while (true) {
Socket client = server.accept ();
System.out.println ("Accepted from " + client.getInetAddress ());
ChatHandler handler = new ChatHandler (client);
handler.start ();
}
}
}