Method displayMessage
When a packet arrives, lines 53–58 call method displayMessage (declared at lines 86–97) to append the packet’s contents to the text area. DatagramPacket method getAddress (line 54) returns an InetAddress object containing the IP address of the computer from which the packet was sent. Method getPort (line 55) returns an integer specifying the port number through which the client computer sent the packet. Method getLength (line 56) returns an integer representing the number of bytes of data received. Method getData (line 57) returns a byte array containing the data. Lines 57–58 initialize a String object using a three-argument constructor that takes a byte array, the offset and the length. This String is then appended to ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access