Coverage Summary for Class: Server (it.polimi.ingsw.server)

Class Class, % Method, % Line, %
Server 0% (0/ 1) 0% (0/ 2) 0% (0/ 11)


1 package it.polimi.ingsw.server; 2  3 import java.io.IOException; 4 import java.net.Inet4Address; 5 import java.net.ServerSocket; 6 import java.net.Socket; 7 import java.net.UnknownHostException; 8 import java.util.concurrent.ExecutorService; 9 import java.util.concurrent.Executors; 10  11 /** 12  * Server Class, Accept new connection 13  */ 14 class Server { 15  16  /** 17  * Server's port 18  */ 19  private static final int PORT = 9090; 20  21  /** 22  * Server socket 23  */ 24  private ServerSocket serverSocket; 25  26  /** 27  * Executor 28  */ 29  private ExecutorService runExecutor = Executors.newFixedThreadPool(64); 30  31  /** 32  * Server Constructor 33  * 34  * @throws IOException 35  */ 36  public Server() throws IOException { 37  this.serverSocket = new ServerSocket(PORT); 38  } 39  40  /** 41  * Server run 42  * 43  * @throws UnknownHostException 44  */ 45  public void run() throws UnknownHostException { 46  System.out.println("Server IP: " + Inet4Address.getLocalHost().getHostAddress() + "\nServer Port: " + PORT); 47  while (true) { 48  try { 49  Socket socket = serverSocket.accept(); 50  Connection connection = new Connection(socket, this); 51  runExecutor.submit(connection); 52  53  } catch (IOException ex) { 54  System.err.println("Connection failed!"); 55  } 56  } 57  } 58  59 }