Beispiel #1
0
 private void readSendPacket(DatagramPacket sendPacket) {
   // print log
   System.out.println("Server: sending a packet...");
   System.out.println("To host: " + sendPacket.getAddress());
   System.out.println("Destination host port: " + sendPacket.getPort());
   Request req = new Request(sendPacket.getData(), sendPacket.getLength());
   String reqString = req.getString();
   byte reqBytes[] = req.getByteArray();
   System.out.print("String: '" + reqString + "'\n");
   System.out.print("Bytes:  '");
   int i = 0;
   while (i < req.getLength()) {
     System.out.print(reqBytes[i++]);
   }
   System.out.print("'\n");
 }
Beispiel #2
0
 private void readReceivePacket(DatagramPacket receivePacket) {
   // print log
   Request req = new Request(receivePacket.getData(), receivePacket.getLength());
   System.out.println("Server: receiving a packet...");
   System.out.println("From host: " + receivePacket.getAddress());
   System.out.println("Host port: " + receivePacket.getPort());
   String reqString = req.getString();
   byte reqBytes[] = req.getByteArray();
   System.out.print("String: '" + reqString + "'\n");
   System.out.print("Bytes:  '");
   int i = 0;
   while (i < req.getLength()) {
     System.out.print(reqBytes[i++]);
   }
   System.out.print("'\n");
   System.out.println("Server: packet received.\n");
 }