You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
65 lines
1.9 KiB
65 lines
1.9 KiB
package com.vertsys;
|
|
|
|
import java.io.IOException;
|
|
import java.net.ServerSocket;
|
|
import java.net.Socket;
|
|
import java.util.ArrayList;
|
|
|
|
|
|
public class Server {
|
|
protected static ServerSocket sock;
|
|
protected static ArrayList<String> messages = new ArrayList<>();
|
|
protected static ArrayList<Socket> clients = new ArrayList<>();
|
|
// protected static ArrayList<String> messages = new ArrayList<>();
|
|
protected static int port;
|
|
|
|
protected static boolean DEBUG_MODE = true;
|
|
|
|
public static void main(String[] args){
|
|
init(args);
|
|
try {
|
|
sock = new ServerSocket(port);
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
}
|
|
while (true){
|
|
if (DEBUG_MODE)
|
|
System.out.println("Socket opened... Waiting for connections");
|
|
try {
|
|
Socket connSocket = sock.accept();
|
|
clients.add(connSocket);
|
|
new Thread(new ServerThread(connSocket)).start();
|
|
} catch (IOException e){
|
|
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
|
|
public static void init(String[] args){
|
|
|
|
switch (args.length) {
|
|
case 0:
|
|
if (DEBUG_MODE)
|
|
System.out.println("No Parameters. Set port to default values...");
|
|
port = 42424;
|
|
break;
|
|
case 1:
|
|
if (DEBUG_MODE)
|
|
System.out.println("Port as Parameter.");
|
|
port = Integer.parseInt(args[1]);
|
|
if (port < 0) {
|
|
System.err.println("ERROR: Port must be a value >= 0!");
|
|
System.out.println("Usage: java ConcatServer [port]");
|
|
System.exit(-1);
|
|
}
|
|
break;
|
|
|
|
default:
|
|
System.out.println("Usage: java ConcatServer [port]");
|
|
System.exit(0);
|
|
break;
|
|
}
|
|
}
|
|
}
|