how to listen to a port in java

Solutions on MaxInterview for how to listen to a port in java by the best coders in the world

showing results for - "how to listen to a port in java"
Felix
24 Mar 2018
1int portNumber = Integer.parseInt(args[0]);
2
3try ( 
4    ServerSocket serverSocket = new ServerSocket(portNumber);
5    Socket clientSocket = serverSocket.accept();
6    PrintWriter out =
7        new PrintWriter(clientSocket.getOutputStream(), true);
8    BufferedReader in = new BufferedReader(
9        new InputStreamReader(clientSocket.getInputStream()));
10) {
11