java listen on port code example
Example 1: how to listen to a port in java
int portNumber = Integer.parseInt(args[0]);
try (
ServerSocket serverSocket = new ServerSocket(portNumber);
Socket clientSocket = serverSocket.accept();
PrintWriter out =
new PrintWriter(clientSocket.getOutputStream(), true);
BufferedReader in = new BufferedReader(
new InputStreamReader(clientSocket.getInputStream()));
) {
Example 2: listen to port
app.express.listen(PORT, () => {
console.log(`App listening on port ${PORT}`);
});