Java Network Programming by Elliotte Rusty Harold Here are the changes made in the 4/99 printing: {23} Changed Figure 2-3. It now reads: B 1 0 C 1 1 0 D 1 1 1 0 E 1 1 1 1 0 {52} In step 4 deleted

GET /javafaq/classes/animation.class HTTP/1.0 and the blank line that followed it. {54} "Of these eight" changed to "Of these ten" {68} In the first paragraph, changed "polymorphic newInetAddressFactory() methods." to "overloaded newInetAddressFactory() methods." (68) Example 4-8: changed // Use a byte array like {199, 1, 32, 90} to build // an InetAddressObject to // Use a byte array like {(byte) 199, (byte) 1, (byte) 32, (byte) 90} // to build an InetAddressObject {70} Para. 1, line 4 used to read: "we add a polymorphic newInetAddress() method" It now reads: "we add an overloaded newInetAddress() method" {74} Para. -1, line -3 used to read "11:53 PM"; changed to "10:53 PM" {110} In code 1, line 1: the space after "paint" was deleted. {113} In code 3 & 4: deleted spurious space after "(" {152} The 2nd code example used to read: "to Ora" It now reads: "toOra" {155} In Example 7-3, the line used to read: theSocket = new Socket(host, i) It now reads: theSocket = new Socket(theAddress, i) {199} In Example 8-5, changed static String theData; to static String theData = ""; in the first line of the class <209> Changed code. It now reads: --------------cut here----------------------- public void run() { String method; String file=""; String ct; String version = ""; File theFile; try { PrintStream os = new PrintStream(theConnection.getOutputStream()); DataInputStream is = new DataInputStream(theConnection.getInputStream()); String get = is.readLine(); StringTokenizer st = new StringTokenizer(get); method = st.nextToken(); if (st.hasMoreTokens()) { file = st.nextToken(); if (file.endsWith("/")) file += indexfile; } if (st.hasMoreTokens()) version = st.nextToken(); if (method.equals("GET")) { ct = guessContentTypeFromName(file); // loop through the rest of the input lines while ((get = is.readLine()) != null) { if (get.trim().equals("")) break; } try { theFile = new File(docroot, file.substring(1,file.length())); FileInputStream fis = new FileInputStream(theFile); byte[] theData = new byte[(int) theFile.length()]; // need to check the number of bytes read here fis.read(theData); fis.close(); if (version.startsWith("HTTP/")) { // send a MIME header os.print("HTTP/1.0 200 OK\r\n"); Date now = new Date(); os.print("Date: " + now + "\r\n"); os.print("Server: jhttp 1.0\r\n"); os.print("Content-length: " + theData.length + "\r\n"); os.print("Content-type: " + ct + "\r\n\r\n"); } // end try // send the file os.write(theData); os.close(); } // end try catch (IOException e) { // can't find the file if (version.startsWith("HTTP/")) { // send a MIME header os.print("HTTP/1.0 404 File Not Found\r\n"); Date now = new Date(); os.print("Date: " + now + "\r\n"); os.print("Server: jhttp 1.0\r\n"); os.print("Content-type: text/html" + "\r\n\r\n"); } os.println("File Not Found"); os.println("

HTTP Error 404: File Not Found

"); os.close(); } } else { // method does not equal "GET" if (version.startsWith("HTTP/")) { // send a MIME header os.print("HTTP/1.0 501 Not Implemented\r\n"); Date now = new Date(); os.print("Date: " + now + "\r\n"); os.print("Server: jhttp 1.0\r\n"); os.print("Content-type: text/html" + "\r\n\r\n"); } os.println("Not Implemented"); os.println("

HTTP Error 501: Not Implemented

"); os.close(); } } catch (IOException e) { } try { theConnection.close(); } catch (IOException e) { } } <226> In Examples 9-7: Changed try { DatagramSocket ds = new DatagramSocket(port); DatagramPacket dp = new DatagramPacket(buffer, buffer.length); while (true) { try { to try { DatagramSocket ds = new DatagramSocket(port); while (true) { DatagramPacket dp = new DatagramPacket(buffer, buffer.length); try { {236} In paragraph 3, changed "If the buffer length is not specified, 512 bytes is used." to: "If the buffer length is not specified 65,507 bytes is used." {237} Example 9-12: changed incoming = new DatagramPacket(buffer, buffer.length); while (true) { to while (true) { incoming = new DatagramPacket(buffer, buffer.length); {238} Example 9-13: changed "protected static int defaultPort = 9;" to static { defaultPort = 13; } {238} Example 9-14: changed "protected static int defaultPort = 9;" to static { defaultPort = 13; } {238} Example 9-15: changed "protected static int defaultPort = 7;" to static { defaultPort = 7; } {239} Example 9-15: changed "protected static int defaultPort = 13;" to static { defaultPort = 13; } {242} Deleted the line eot.stop(); in Example 9-18. {243} Example 9-19

Changed buffer = new byte[65507]; to byte[] buffer = new byte[65507]; {252} Changed uc.getHeaderField("content-encoding")); to uc.getHeaderField("content-encoding"); That is, deleted the extra closing parenthesis. {253} Changed "The first header is zero" to "The first MIME header is one." {276} In paragraph 3: changed "The request above contains two name-value pairs, separated by ampersands." to "The request above contains two name-value pairs, separated by an ampersand." {278} In example 10-16, deleted the line "int cl = query.length();" {284} In list item number 3, changed sun.net.www.protocol.Handler to sun.net.www.protocol.protocol.Handler {288} In paragraph 4: changed "This method must be overridden in each subclass of URLConnection." to "This method must be overridden in each subclass of URLStreamHandler." {291} In Example 11-2 at the top of the page, changed return text/plain; to return "text/plain; {293} The text used to read: "of the createURLStreamHandlerFactory interface" It now reads: "of the URLStreamHandlerFactory interface" {311} Example 12-2: In the test() method, deleted "String theLine;"