Corrections to Chapter 13 of Java Network Programming, 3rd Edition, UDP Datagrams and Sockets

p. 426: Figure 13-1 shows the destination port twice. The second one should be a checksum. Here's the corrected picture:

Structure of a UDP datagram

There's also an extraneous i at the bottom left hand corner of the picture. That shouldn't be there.

pp. 439-441: Example 13-3 and 13-4 share a mutual bug. Both assume they're using the local host's default encoding. However, if these two programs run on different hosts (for instance, one is a Japanese system and one is a French system) that may well not be the same for each. The encoding needs to be explicitly specified in both programs. On p. 439 in Example 13-3 change

byte[] data = theLine.getBytes()


byte[] data = theLine.getBytes("UTF-8")

On p. 441 in Example 13-4 change

String s = new String(packet.getData(), 0, packet.getLength())


String s = new String(packet.getData(), 0, packet.getLength(), "UTF-8")

This will allow the two hosts to exchange data regardless of differing encodings.

[ Java Network Programming Corrections | Java Network Programming Home Page | Table of Contents | Examples | Order from Amazon ] ]

Copyright 2004-2006 Elliotte Rusty Harold
Last Modified June 3, 2006