Creates welcome socket and starts update loop to handle arbitrary sequence of clients making requests. @param port a port number @throws Exception
(int port)
| 32 | * @throws Exception |
| 33 | */ |
| 34 | private static void start(int port) throws Exception { |
| 35 | connectionSocket = null; |
| 36 | ServerSocket serverSocket = new ServerSocket(port, 0); |
| 37 | boolean complete; |
| 38 | while (true) { |
| 39 | if (connectionSocket == null) { |
| 40 | connectionSocket = serverSocket.accept(); |
| 41 | } |
| 42 | download(); |
| 43 | if (System.in.available() > 0) { |
| 44 | complete = download(); |
| 45 | } else { |
| 46 | complete = upload(); |
| 47 | } |
| 48 | if (complete) { |
| 49 | break; |
| 50 | } |
| 51 | } |
| 52 | connectionSocket.close(); |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * In download mode, server reads data from the socket and writes it to standard output. |