In download mode, server reads data from the socket and writes it to standard output. @throws Exception
()
| 46 | * @throws Exception |
| 47 | */ |
| 48 | private static void download() throws Exception { |
| 49 | if (!pinged) { |
| 50 | byte[] receiveData = new byte[1024]; |
| 51 | pingPacket = new DatagramPacket(receiveData, receiveData.length); |
| 52 | serverSocket.receive(pingPacket); |
| 53 | pinged = true; |
| 54 | } |
| 55 | Scanner input = new Scanner(System.in); |
| 56 | while (input.hasNextLine()) { |
| 57 | byte[] sendData = input.nextLine().getBytes(); |
| 58 | serverSocket.send(new DatagramPacket(sendData, sendData.length, pingPacket.getAddress(), pingPacket.getPort())); |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * In upload mode, server reads data from its standard input device and writes it to the socket. |