In download mode, client reads data from the socket and writes it to standard output. @throws Exception
(int port)
| 46 | * @throws Exception |
| 47 | */ |
| 48 | private static void download(int port) throws Exception { |
| 49 | if (!pinged) { |
| 50 | byte[] sendData = "".getBytes(); |
| 51 | DatagramPacket pingPacket = new DatagramPacket(sendData, sendData.length, ipAddress, port); |
| 52 | clientSocket.send(pingPacket); |
| 53 | pinged = true; |
| 54 | } |
| 55 | byte[] receiveData = new byte[4096]; |
| 56 | DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length); |
| 57 | clientSocket.receive(receivePacket); |
| 58 | System.out.println(new String(receivePacket.getData()).trim()); |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * In upload mode, client reads data from its standard input device and writes it to the socket. |