0
package server;
import java.net.*; // for network
import java.util.*; // for utilities
import java.io.*; // for streams
import server.ex12ClientThread;
public class ex12Server implements ex12Constants
{
public static void main(String args[])
{
int well_known_port = SERVERPORT; // default port value
ServerSocket serverSock = null;
ex12ClientThread thread = null;
try { // to get a port number
if (args.length > 0)
{
well_known_port = Integer.parseInt(args[0]);
//initialises port number to connect to
}
} catch (NumberFormatException e) {} // do nothing accept default.
try
{
serverSock = new ServerSocket(well_known_port, 10) ;
// information to log file (ie screen)
System.out.println("ServerSocket " + serverSock.toString());
System.out.println("Entering server loop");
while(true) // Main Server loop
{
Socket clientSocket = serverSock.accept();
thread = new ex12ClientThread(clientSocket);
thread.setDaemon(true);
thread.start();
}
} catch(Exception e)
{
System.err.println("Socket Error!!!.") ;
System.exit(1) ;
}
finally
{
try
{
serverSock.close();
}
catch (IOException e) {}
}
}
}
請包括任何_exceptions_被引發或_console output_ – mre 2011-05-04 13:36:07