Created
June 17, 2020 16:44
-
-
Save recursivecodes/86d15b8b4340549bbd7335a194aca5c3 to your computer and use it in GitHub Desktop.
Main.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void main(String[] args) throws IOException { | |
Logger logger = LoggerFactory.getLogger(Main.class); | |
int port = Integer.parseInt( System.getProperty("port", "30000") ); | |
socketServer = new ServerSocket(port); | |
logger.info("Listening on localhost:{}...", port); | |
Runtime.getRuntime().addShutdownHook(new Thread(() -> { | |
logger.info("Server shutting down. Goodbye..."); | |
try { | |
socketServer.close(); | |
} | |
catch (IOException e) { | |
e.printStackTrace(); | |
} | |
})); | |
//noinspection InfiniteLoopStatement | |
while(true) { | |
Socket socket = socketServer.accept(); | |
Runnable messageHandler = new MessageHandler(socket); | |
new Thread(messageHandler).start(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment