Graphics Programs Reference
In-Depth Information
All of this packet encapsulation makes up a complex language that hosts
on the Internet (and other types of networks) use to communicate with each
other. These protocols are programmed into routers, firewalls, and your
computer's operating system so they can communicate. Programs that use
networking, such as web browsers and email clients, need to interface with
the operating system which handles the network communications. Since the
operating system takes care of the details of network encapsulation, writing
network programs is just a matter of using the network interface of the OS.
0x420
Sockets
A socket is a standard way to perform network communication through the
OS. A socket can be thought of as an endpoint to a connection, like a socket
on an operator's switchboard. But these sockets are just a programmer's
abstraction that takes care of all the nitty-gritty details of the OSI model
described above. To the programmer, a socket can be used to send or receive
data over a network. This data is transmitted at the session layer (5), above
the lower layers (handled by the operating system), which take care of
routing. There are several different types of sockets that determine the
structure of the transport layer (4). The most common types are stream
sockets and datagram sockets.
Stream sockets provide reliable two-way communication similar to when
you call someone on the phone. One side initiates the connection to the
other, and after the connection is established, either side can communicate
to the other. In addition, there is immediate confirmation that what you said
actually reached its destination. Stream sockets use a standard communica-
tion protocol called Transmission Control Protocol (TCP), which exists on
the transport layer (4) of the OSI model. On computer networks, data is
usually transmitted in chunks called packets. TCP is designed so that the
packets of data will arrive without errors and in sequence, like words
arriving at the other end in the order they were spoken when you are
talking on the telephone. Webservers, mail servers, and their respective
client applications all use TCP and stream sockets to communicate.
Another common type of socket is a datagram socket. Communicating
with a datagram socket is more like mailing a letter than making a phone call.
The connection is one-way only and unreliable. If you mail several letters, you
can't be sure that they arrived in the same order, or even that they reached
their destination at all. The postal service is pretty reliable; the Internet, how-
ever, is not. Datagram sockets use another standard protocol called UDP
instead of TCP on the transport layer (4). UDP stands for User Datagram
Protocol, implying that it can be used to create custom protocols. This
protocol is very basic and lightweight, with few safeguards built into it. It's
not a real connection, just a basic method for sending data from one point
to another. With datagram sockets, there is very little overhead in the protocol,
but the protocol doesn't do much. If your program needs to confirm that a
packet was received by the other side, the other side must be coded to send
back an acknowledgment packet. In some cases packet loss is acceptable.
Search WWH ::




Custom Search