We Talk Coding

How to take a port # from KB to use as ServerSocket port in Java WebServers. Example code better?

Confused with how to use BufferedReader and insert the entered port as the ServerSocket port no.

Public Comments

  1. BufferedReader stdin = new BufferedReader( new InputStreamReader(System.in)); int port= -1; while(port == -1){ try { String portText = stdin.readLine();//returns when hit "Enter" port = Integer.parseInt(portText); } catch (NumberFormatException nfe) { System.out.println("Must be digits!"); System.out.println("Try again..."); } }//end while ServerSocket ss = new ServerSocket(port);
Powered by Yahoo! Answers