Programming Sockets with PERL - Types of Sockets (
Page 2 of 5 )
There are just two types of sockets: connection
oriented and connection-less. There are other types but this classification is
fair enough to get started, a socket has a domain (UNIX or internet), a connection
type (connection oriented or connection less) and a protocol (TCP or UDP).
A connection oriented or a stream socket is a reliable two way communication.
If you send three packets, say 1, 2 and 3, they are received in the same order
they were sent. They achieve this high level of transmission quality by using
TCP for error free reliable communication. The ubiquitous telnet application uses
stream sockets.
The connection-less sockets or stream-less sockets use IP for routing but use
the UDP. They are connectionless, since the connection need not be open as in
stream sockets, the packet formed is given a destination IP address and than transmitted.
This method is mostly used for packet-to-packet transfer as in ftp applications.
How a Packet is Formed
We will use an example of UDP packet for some light stuff on networking theory.
It's Data Encapsulation. A packet is formed by encapsulating the data in a header
at each level as it passes through the layers (protocol stack). At the receiving
end the headers are stripped off as the packet travels up the layers to get the
data.
Basically, at each layer, the protocol adds a header to the payload to perform
the required functionality.
Client Server Architecture
It's a client-server world, today. Just about everything on the network deals
with client processes talking to server processes and vice versa. Take the ubiquitous
telnet, for instance. When you connect to a remote host on port 23 with telnet
(the client), a program on that host (called telnetd, the server) springs to life.
It handles the incoming telnet connection, sets up a login prompt, etc. Note that
the client-server pair can speak in streaming or stream-less, or anything else
(as long as they are speaking the same thing).
Some good examples of client-server pairs are telnet/telnetd, ftp/ftpd.