/** * Terminates the work of the socket server. */ public void terminate() { if (!isNetworkThreadRunning()) { LOGGER.warn("Could not terminate network thread. Network thread is not running."); return; } LOGGER.info("Stopping socket server..."); connectionHandler.terminate(); try { socketServerThread.join(SOCKET_THREAD_KILL_TIMEOUT); LOGGER.debug("Network thread should be stopped now..."); } catch (InterruptedException e) { LOGGER.debug("Error stopping network thread...", e); } try { connectionHandler.terminateSocketServer(); LOGGER.info("Socket connection stopped successfully!"); } catch (IOException e) { LOGGER.error("Could not close opened connection.", e); } } }