Java Support For Network Programming


Internet Networking Protocols — Nuts & Bolts

This section discusses the concepts associated with the Internet protocols and related terminology in greater detail. You’ll find this background information helpful when navigating your way through the java.net package looking for a solution to your network programming problem.

The Internet Protocols: TCP, UDP, And IP

The Internet protocols facilitate the transmission and reception of data between participating client and server applications in a packet-switched network environment. The term packet-switched network means that data traveling along network pathways is divided into small, routable packages referred to as packets. If a communication link between two points on a network goes down the packets can be routed through remaining network connections to their intended destination.

The Internet protocols work together as a layered protocol stack as is shown in figure 19-16.

image from book
Figure 19-16: TCP/IP Protocol Stack

The layered protocol stack consists of the application layer, the transport layer, the network layer, the data link layer, and the physical layer. Each layer in the protocol stack provides a set of services to the layer above it. Several examples of protocols that may be employed at each level in the application stack are also shown in figure 19-16. For more information on protocols not discussed in this chapter please consult the sources listed in the references section.

The Application Layer

The application layer represents any internet enabled application that requires the services of the transport layer. Typical applications you may be familiar with include File Transfer Protocol (FTP), Hypertext Transfer Protocol (HTTP), TELNET, or a custom internet application such as one you might write. The application layer relies on services provided by the transport layer.

Transport layer

The purpose of the transport layer is to provide host-to-host, connection-oriented, data transmission service to the application layer. Two internet protocols that function at the transport layer include the Transmission Control Protocol (TCP) and the User Datagram Protocol (UDP). Java supports both of these protocols directly in that normal network communication takes place using TCP but UDP can be utilized if required.

Transmission Control Protocol (TCP)

The purpose of TCP is to provide highly-reliable, host-to-host communication. To achieve this TCP manages several important issues including basic data transfer, reliability, flow control, multiplexing, connections, and precedence and security.

The sending and receiving TCP modules work together to achieve the level of service mandated by the TCP protocol. The sending TCP module packages octets of data into segments which it forwards to the network layer and the Internet Protocol (IP) for further transmission. TCP tags each octet with a sequence number. The receiving TCP module signals an acknowledgement when it receives each segment and orders the octets according to sequence number, eliminating duplicates and properly handling those that may have been received out of order.

In short — TCP guarantees data delivery and saves you the worry.

User Datagram Protocol (UDP)

UDP is used to send and receive data as quickly as possible without the overhead incurred when using TCP. UDP is an extremely lightweight protocol when compared with TCP. It provides direct access to the IP datagram level. However, the quick data transmission provided by UDP comes at a price. Data is not guaranteed to arrive at its intended destination when sent via UDP.

Now, you might ask yourself, “Self, what’s UDP good for?” Generally speaking, any application that needs to send data quickly and doesn’t particularly care about lost datagrams might stand to benefit from using UDP. Examples include data streams where previously sent data is of little or no use because of its age. (i.e., stock market quote streams, voice transmissions, etc.)

In short — UDP is faster than TCP but unreliable.

Network Layer

The network layer is responsible for the routing of data traffic between internet hosts. These hosts can be located on a local area network or on another network somewhere on the Internet. The Internet Protocol (IP) resides at this layer and provides data routing services to the transport layer protocols TCP or UDP.

Internet Protocol (IP)

The Internet Protocol (IP) is a connectionless service that permits the exchange of data between hosts without a prior call setup. (Hence the term connectionless.) It packages data submitted by TCP or UDP into blocks called data-grams. IP uses IP addresses and routing tables to properly route datagrams to their intended destination networks.

Data Link & Physical Layers

The data link and physical layers are the lowest layers of the networking protocol stack.

The Data Link Layer

The data link layer sits below the network layer and is responsible for the transmission of data across a particular communications link. It provides for flow control and error correction of transmitted data. An example protocol that operates at the data link layer is Ethernet.

The Physical Layer

The physical layer is responsible for the actual transmission of data across the physical communication lines. Physical layer protocols concern themselves with the types of signals used to transmit data (i.e., electrical, optical, etc.) and the type of media used to convey the signals (i.e., fiber optic, twisted pair, coaxial, etc.).

Putting It All Together

Computers that participate in a TCP/IP networking environment must be running an instance of the TCP/IP protocol stack as is illustrated in figure 19-17.

image from book
Figure 19-17: Internet Protocol Stack Operations

Referring to figure 19-17 — When host computer A sends data to host computer B via the Internet the data is passed from the application layer to the physical layer on host computer A and sent to the gateway that links the two subnetworks. At the gateway the packets are passed back up to the network layer to determine the forwarding address and repackaged and sent to the destination computer. When the packets arrive at host computer B they are passed back up the protocol stack and the original data is presented to the application layer.

What You Need To Know

Now that you have some idea of what’s involved with moving data between host computers on the Internet or on a local area network using the Internet protocols you can pretty much forget about all these nasty details. Java provides a set of classes in the java.net package that makes network programming easy. Java’s support for network programming is discussed in the next section.

Quick Review

The Internet protocols facilitate the transmission and reception of data between participating client and server applications in a packet-switched network environment. The term packet-switched network means that data traveling along network pathways is divided into small, routable packages referred to as packets. If a communication link between two points on a network goes down the packets can be routed through remaining network connections to their intended destination.

The Internet protocols work together as a layered protocol stack. The layered protocol stack consists of the application layer, the transport layer, the network layer, the data link layer, and the physical layer. Each layer in the protocol stack provides a set of services to the layer above it.

The application layer represents any Internet enabled application that requires the services of the transport layer. The purpose of the transport layer is to provide host-to-host, connection-oriented, data transmission service to the application layer. Two Internet protocols that function at the transport layer include the Transmission Control Protocol (TCP) and the User Datagram Protocol (UDP). TCP guarantees data delivery and saves you the worry. UDP is faster than TCP but unreliable.

The network layer is responsible for the routing of data traffic between Internet hosts. The Internet Protocol (IP) is a connectionless service that permits the exchange of data between hosts without a prior call setup. (Hence the term connectionless.) It packages data submitted by TCP or UDP into blocks called datagrams. IP uses IP addresses and routing tables to properly route datagrams to their intended destination networks.

The data link and physical layers are the lowest layers of the networking protocol stack. The data link layer sits below the network layer and is responsible for the transmission of data across a particular communications link. The physical layer is responsible for the actual transmission of data across the physical communication lines.

Computers that participate in a TCP/IP networking environment must be running an instance of the TCP/IP protocol stack. The TCP/IP protocol stack is part of a computer’s operating system.




Java For Artists(c) The Art, Philosophy, and Science of Object-Oriented Programming
Java For Artists: The Art, Philosophy, And Science Of Object-Oriented Programming
ISBN: 1932504052
EAN: 2147483647
Year: 2007
Pages: 452

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net