Chapter 24

Internet Networking


Chapter Goals

The Internet Protocol

Data Transmission

Sending Data from A to B across the Internet

Two Computers Communicating across the Internet

Destination Address

Domain Naming Service

Packets

Transmission Control Protocol

TCP's Job

Port Numbers

Contents of TCP Packet

Self Check

  1. What is the difference between an IP address and a domain name?
  2. Why do some streaming media services not use TCP?

Answers

  1. An IP address is a numerical address, consisting of four or sixteen bytes. A domain name is an alphanumeric string that is associated with an IP address.
  2. TCP is reliable but somewhat slow. When sending sounds or images in real time, it is acceptable if a small amount of the data is lost. But there is no point in transmitting data that is late.

The OSI Reference Model

Application Level Protocols

Hypertext Transfer Protocol (HTTP)

Browser Steps

  1. Examines the part of the URL between the double slash and the first single slash

Browser Steps

  1. From the http: prefix, browser deduces that the protocol is HTTP
  2. It establishes a TCP/IP connection to port 80 at IP address obtained in step 1
  3. It deduces from the /index.html that you want to see the file /index.html
    and sends this request formatted as an HTTP command through the established connection
     
    GET /index.html HTTP/1.0
    a blank line

Browser Steps

  1. Web server running on computer whose IP Address was obtained above receives the request
  2. The browser displays the contents of the file for you to see

Telnet

Telnet

Web Server Response in Telnet

HTTP

HTTP Commands

CommandMeaning
GETReturn the requested item
HEADRequest only the header information of an item
OPTIONSRequest communications options of an item
POSTSupply input to a server-side command and return the result
PUTStore an item on the server
DELETEDelete an item on the server
TRACETrace server communication

Application Level Protocols

A Sample POP Session


Self Check

  1. Why don't you need to know about HTTP when you use a web browser?
  2. Why is it important that you don't make typing errors when you type HTTP commands in Telnet?

Answers

  1. The browser software translates your requests (typed URLs and mouse clicks on links) into HTTP commands that it sends to the appropriate web servers.
  2. All keystrokes that you type, including the backspace key, are sent to the server. The server does not recognize a character sequence such as G W Backspace E T as a valid command.

A Client Program – Sockets

A Client Program – Input and Output Streams

Client and Server Sockets

A Client Program – Scanners and Writers

A Client Program – WebGet

File WebGet.java

Output

Getting / from java.sun.com
HTTP/1.1 200 OK
Server: Netscape-Enterprise/6.0
Date: Wed, 21 Jul 2004 23:47:27 GMT
Content-type: text/html;charset=ISO-8859-1
Connection: close

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Java Technology</title>
. . .
</body>
</html>

Self Check

  1. What happens if you call WebGet with a nonexistent resource, such as wombat.html at java.sun.com?
  2. How do you open a socket to read e-mail from the POP server at e-mail.sjsu.edu?

Answers

  1. The program makes a connection to the server, sends the GET request, and prints the error message that the server returns.
  2. Socket s = new Socket("e-mail.sjsu.edu", 110);

A Server Program

Simple Bank Access Protocol

Client Request Server Response Meaning
BALANCE n n and the balance Get the balance of account n
DEPOSIT n a n and the new balance Deposit amount a into account n
WITHDRAW n a n and the new balance Withdraw amount a from account n
QUIT None Quit the connection

A Server Program

A Server Program – BankService

A Server Program – executeCommand

A Server Program

A Server Program – Threads

Using the Telnet Program to Connect to the BankServer

File BankServer.java

File BankService.java

File Bank.java

File BankClient.java

Output

Sending: DEPOSIT 3 1000
Receiving: 3 1000.0
Sending: WITHDRAW 3 500
Receiving: 3 500.0
Sending: QUIT

Self Check

  1. Why didn't we choose port 80 for the bank server?
  2. Can you read data from a server socket?

Answers

  1. Port 80 is the standard port for HTTP. If a web server is running on the same computer, then one can't open a server socket on an open port.
  2. No, a server socket just waits for a connection and yields a regular Socket object when a client has connected. You use that socket object to read the data that the client sends.

URL Connections

URL Connections

HTTP Commands

command
request properties
blank line

URLConnection Class

Server Response

Retrieving Response Code and Message

Retrieve Other Response Information from URLConnection

File URLGet.java

Output

Using http://java.sun.com/
200 OK
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Java Technology</title>
. . .
</body>
</html>

Self Check

  1. Why is it better to use an URLConnection instead of a socket when reading data from a web server?
  2. What happens if you use the URLGet program to request an image (such as http://java.sun.com/im/logo_java.gif)?

Answers

  1. The URLConnection class understands the HTTP protocol, freeing you from assembling requests and analyzing response headers.
  2. The bytes that encode the images are displayed on the console, but they will appear to be random gibberish.