int thePort;
ServerSocket ss;
Socket theConnection;
try {
thePort = Integer.parseInt(args[0]);
}
catch (Exception e) {
thePort = 0;
}
try {
ss = new ServerSocket(thePort);
System.out.println("Listening for connections on port " + ss.getLocalPort());
while (true) {
theConnection = ss.accept();
System.out.println("Connection established with " + theConnection);
InputThread it = new InputThread(theConnection.getInputStream());
it.start();
OutputThread ot = new OutputThread(theConnection.getOutputStream(), it);
ot.start();
// need to wait for ot and it to finish
try {
ot.join();
it.join();
}
catch (InterruptedException e) {
}
}
}
catch (IOException e) {
}