45 lines
1.0 KiB
Java
45 lines
1.0 KiB
Java
|
|
import java.io.*;
|
|
import java.util.*;
|
|
import java.net.*;
|
|
|
|
// Server class
|
|
public class Server {
|
|
|
|
final public static String storageDir = System.getProperty("user.dir") + "/../storage";
|
|
|
|
public static Vector<Connection> connections = new Vector<>();
|
|
|
|
public static void main(String[] args) throws IOException {
|
|
|
|
int port;
|
|
|
|
if (args.length > 0) {
|
|
port = Integer.parseInt(args[0]);
|
|
} else {
|
|
System.out.println("Uzywam: java Server <port>");
|
|
return;
|
|
}
|
|
|
|
ServerSocket serverSocket = new ServerSocket(port);
|
|
System.out.println("Start serwera na porcie "+port);
|
|
|
|
Socket socket;
|
|
|
|
while (true) {
|
|
// Akceptowanie nadchodzacego zapytania
|
|
socket = serverSocket.accept();
|
|
|
|
System.out.println("Nowe polaczenie: " + socket);
|
|
|
|
Connection connection = new Connection(socket);
|
|
|
|
Thread thread = new Thread(connection);
|
|
|
|
connections.add(connection);
|
|
|
|
thread.start();
|
|
}
|
|
}
|
|
}
|