Hardware Reference
In-Depth Information
Transmission Control Protocol: Sockets & Sessions
Each time a client connects to a web server, the connection that's opened uses a
protocol called Transmission Control Protocol , or TCP . TCP is a protocol that specifies how
objects on the Internet open, maintain, and close a connection that will involve multiple
exchanges of messages. The connection made between any two objects using TCP is
called a socket . A socket is like a pipe joining the two objects. It allows data to flow back
and forth between them as long as the connection is maintained. Both sides need to
keep the connection open in order for it to work.
For example, think about the exchanges between a
web client and server that you saw in the previous two
chapters. The pipe is opened when the server acknowledg-
es the client's contact, and it remains open until the server
has finished sending the file. If there are multiple files
needed for a web page, such as images and style sheets,
then multiple socket connections are opened and closed.
The complexity of TCP is worthwhile when you're exchang-
ing critical data. For example, in an email, every byte is a
character in the message. If you drop a couple of bytes,
you could lose crucial information. The error-checking of
TCP does slow things down a little, though, and if you want
to send messages to multiple receivers, you have to open a
separate socket connection to each one.
There's a lot going on behind the scenes of a socket con-
nection. The exchange of data over a TCP connection can
range in size anywhere from a few bytes to a few terabytes
or more. All that data is sent in discrete packets, and the
packets are sent by the best route from one end to the
other.
There's a simpler type of transmission protocol that's
also common on the Net: User Datagram Protocol (UDP) .
Where TCP communication is based on sockets and
sessions, UDP is based only on the exchange of packets.
You'll learn more about it in Chapter 7.
X
NOTE: “Best” is a deliberately vague term: network hardware cal-
culates the optimal route is differently, which involves a variety of
metrics (such as the number of hops between two points, as well
as the available bandwidth and reliability of a
given path).
The period between the opening of a socket and the suc-
cessful close of the socket is called a session . During the
session, the program that maintains the socket tracks the
status of the connection (open or closed) and the port
number; counts the number of packets sent and received;
notes the order of the packets and sees to it that packets
are presented in the right order, even if the later packets
arrive first; and accounts for any missing packets by
requesting that they be resent. All of that is taken care of
for you when you use a TCP/IP stack like the Net library
in Processing or the firmware on the Arduino Ethernet
boards you first saw in Chapter 4.
Search WWH ::




Custom Search