forked from Cockadoodle/KOProject
47 lines
1.6 KiB
Java
47 lines
1.6 KiB
Java
|
package com.collibra.server;
|
||
|
|
||
|
import java.net.*;
|
||
|
import java.io.*;
|
||
|
|
||
|
|
||
|
/**
|
||
|
* A simple TCP socket server that is accepting client connections in parallel, on the specified port: {@value #PORT}.
|
||
|
* If client stays inactive for the time of the timeout: {@value #TIMEOUT}, it gets disconnected.
|
||
|
* Debug {@value #DEBUG} is used to display the client - server communication in the console.
|
||
|
* Creates a directed weighted GRAPH, that is going to be used for calculations by the clients.
|
||
|
*
|
||
|
* @version 1.0
|
||
|
* @author Yordan Kirov
|
||
|
* @since 21/11/2018
|
||
|
*/
|
||
|
public class Server {
|
||
|
|
||
|
/** The PORT on which the server is running. Hardcoded to 50000. */
|
||
|
private static final int PORT = 50000;
|
||
|
|
||
|
/** The timeout of every client connection to the server. Hardcoded to 30000 MS. */
|
||
|
private static final int TIMEOUT = 30000;
|
||
|
|
||
|
/** Directed weighted graph, that is going to be used for calculations by the clients. */
|
||
|
static final Graph<String> GRAPH = new Graph<>();
|
||
|
|
||
|
/** Debug {@value #DEBUG} is used to display the client - server communication in the console. */
|
||
|
static final boolean DEBUG=false;
|
||
|
|
||
|
public static void main(String[] args) {
|
||
|
System.out.println("The server is listening...");
|
||
|
|
||
|
try (ServerSocket serverSocket = new ServerSocket(PORT)) {
|
||
|
while (true) {
|
||
|
Socket socket = serverSocket.accept();
|
||
|
socket.setSoTimeout(TIMEOUT);
|
||
|
|
||
|
ClientSessionThread st = new ClientSessionThread(socket);
|
||
|
st.start();
|
||
|
}
|
||
|
} catch (IOException e) {
|
||
|
e.printStackTrace();
|
||
|
}
|
||
|
}
|
||
|
}
|