public ChatServer(int port) { try { System.out.println("Binding to port " + port + ", please wait ..."); server = new ServerSocket(port); System.out.println("Server started: " + server); start(); } catch (IOException ioe) { System.out.println("Can not bind to port " + port + ": " + ioe.getMessage()); } }
public ChatServer(int port) { try { System.out.println("Listening on port " + port); server = new ServerSocket(port); System.out.println("Server started: " + server); start(); } catch (IOException ioe) { System.out.println(ioe); } }
/** * Bootstraps the chat server * * @param args Optional port number as command line argument */ public static void main(String[] args) { int port = DEFAULT_PORT; try { if (args.length > 0) { port = Integer.parseInt(args[0]); } ChatServer chatServer = new ChatServer(); chatServer.start(port); } catch (NumberFormatException ex) { System.out.println("Usage: java ChatServer [port_number]"); System.exit(1); } }