Java Reference
In-Depth Information
Note The 32-bit addressing scheme used by TCP/IP has been around since the 1970s. With more and
more devices requiring Internet addresses, it is estimated that all currently available addresses will be used
somewhere between 2016 and 2023 (however, previous estimates on Internet growth have been far below
reality, so this figure is not to be relied on). To alleviate this problem, a new addressing scheme has been
recommended and is slowly being implemented. The 32-bit addressing scheme is known as IPv4, and the
new addressing scheme is known as IPv6. Java supports both schemes with the Inet4Address class and
Inet6Address classes, respectively. In this chapter we will be using IPv4 as this is the most common
addressing scheme currently in use.
TCP and UDP Sockets Overview
Over the years programming has evolved from manually setting binary instructions (1GL or
first-generation languages), through assembly language (2GL), human-readable languages
( Java, C++), and specification languages like SQL (4GL). The later languages do not eliminate
the need for the lower-level languages—they just do the hard work of translating the program-
mer's code into lower-level code. For example, when programming in Java your code will be
translated into bytecode by the Java compiler (corresponding roughly to the output from an
assembly language program), which is later translated into the binary instructions for the
computer by the JVM. While you can still find work as a machine language programmer, many
programmers find that such work is slow and error prone—working in a higher-level language
such as Java can greatly improve productivity and quality of work.
Similarly, network protocols have evolved over the years, so that we no longer need to
worry ourselves with the lowest-level network details. When you are programming your Java
program, you typically do not care how to physically send signals over a piece of wire (or other
medium), nor do you care whether your computers are communicating over an Ethernet or a
Token Ring network; all you care about is how to make the connection. Finally, in order to use
sockets, we will be using IP rather than one of the other network layers (X.25, ICMP, IPX). But
even having chosen to use sockets, leaving all the low-level communication to the IP layer and
layers beneath it, we still have a choice between TCP and UDP sockets.
UDP Sockets
User Datagram Protocol (UDP) enables machines on a network to send datagram packets to
each other. UDP sockets work in much the same way as the U.S. postal system. Messages, or
letters, are sent to a particular address and an immediate response by the server, or addressee,
endpoint is not necessary. UDP sockets do not require a two-way connection. Similarly, the
postal system does not require that the recipient be present when a letter is delivered.
Let's consider the mail analogy a little more. A letter is dropped off at a mailbox and deliv-
ered to the stated address. The mail carrier then places the letter in the destination mailbox.
The mail system does not require that someone be there to accept the letter (of course, I real-
ize that sometimes packages require signatures, but for the sake of convenience let's ignore
those kinds of packages for now). Once the individual to whom the letter is addressed returns
home, he or she can then collect the mail.
UDP discards corrupted messages (datagrams) so there is no guarantee that messages
sent via UDP will make it to their final destination, just as there is no guarantee that a letter
Search WWH ::




Custom Search