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

p. 414: In Figure 13-1, change the second occurrence of "destination port" to "checksum" in the UDP header. The corrected figure is:

A diagram of the fields in a UDP header

pp. 427-429: Example 13-3 and 13-4 share a mutual bug. Both assume they're using the local host's default encoding. However, is these two programs run of 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. 427 in Example 13-3 change

byte[] data = theLine.getBytes()


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

On p. 429 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.

p. 433: In the fifth code line, change new ServerSocket(2048) to new DatagramSocket(2048). It should read:

DatagramSocket ds = new DatagramSocket(2048)

p. 448: In the second paragraph, EchoInputThread should be SenderThread.

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

Copyright 2001-2004 Elliotte Rusty Harold
Last Modified November 1, 2004