9/22/2011
Sock-et (noun)
A specially-made or
specially-shaped
hole or set of holes
into which
something is fitted
Example:- eye
socket & electrical
device socket
9/22/2011
An interface between application and network
which is used for communication between
processes
a socket is an abstraction for network
communication, just as a file, is an abstraction
for file system communication
Sockets are used for interprocess communication.
1.
The application creates a socket
2.
The socket type dictates the style of communication
reliable vs. best effort
connection-oriented vs. connectionless
3. Once configured the application:
can pass data to the socket for network transmission
receive data from the socket (transmitted through the
network by some other host)
Most of the interprocess communication follow a Client-Server
Model, where client and server are two separate processes in itself.
Server and Client exchange messages over the network through a
common Socket API (will be discuss in Chapter 2)
9/22/2011
Operation
Explanation
Open
Prepare for input or output
operations.
Close
Stop previous operations and
return resources.
Read
Get data and place in application
memory.
Write
Put data from application memory
and send control.
Control (ioctl)
Set options such as buffer sizes
and connection behavior
File descriptor is simply an integer associated
with an open file
There are 3 standard POSIX file descriptors
which every process should expect to have:
Integer value
Name
Standard Input (stdin)
Standard Output (stdout)
Standard Error (stderr)
9/22/2011
Sockets layer sits on
top of the transport
layer.
Transport layer
provides the transport
protocols.
Network layer provides
routing over the
Internet. This layer is
occupied by the
Internet Protocol, or IP.
Physical layer driver,
introduce packets onto
the physical network.
Layered model of
communication
9/22/2011
Element
Description
Host (Interface)
Network address (a
reachable network node)
Protocol
Specific protocol (such
as TCP or UDP)
Port
Client or server process
endpoint
Graphical view of host/protocol/port
relationship
Hosts are identified by addresses, and for IP
these are called IP addresses.
An IPv4 address (of the version 4 class) is defined
as a 32-bit address. This address is represented
by four 8-bit values. A sample address is
illustrated as follows:
92.168.1.1 or
0xC0A80101
The first value shows the more popular form of
IPv4 addresses, which is easily readable. The
second notation is simply the first address in
hexadecimal format(32 bits wide).
9/22/2011
The protocol specifies the details of
communication over the socket.
Transmission Control Protocol (TCP) is a
stream-based reliable protocol and the
User Datagram Protocol (UDP) is a datagram
(message)-based protocol that can be
unreliable.
Ports are virtual destination points and allow a
node to conduct multiple network
communications simultaneously
think of ports as doors where information can
come and go from a network node
Port numbers below 1024 are reserved for wellknown services (called well-known addresses),
assigned by the IETF.
Port numbers above 1024 are typically used by
applications.
9/22/2011
On Linux systems:
the number of ports is limited to 65,535
many of the lower port numbers are reserved, such as:
port 80 for web servers
port 25 for sending mail
port 23 for telnet servers.
Ports are designated with a colon when describing an
IP address and port pair.
For example, the address 10.0.0.2:80 can be
read as:
port 80 on the address 10.0.0.2,
which would also mean
the web server on 10.0.0.2
since port 80 is typically used by and reserved for web
services.
9/22/2011
Without ports, a network host would be allowed to
provide only one network service at a time.
By allowing the use of ports, a host can
conceivably provide more than 65,000 services at
any time using a given IP address, assuming each
service is offered on a different port.
9/22/2011
{ tcp, 192.168.1.1, 4097 }
This defines the endpoint on the host
identified by the address 192.168.1.1
with the port 4097 using the TCP protocol.
9/22/2011
Step 1
creation of a socket (the communication endpoint)
both the server and client perform this step.
Step2
Binds an address and port to the server so that its
known.
Letting the system choose the port can result in a
service that can be difficult to find (so choose the port
to make easier).
Step 3
Call listen function for the server. This makes the
server accessible (puts it in the listen mode).
Step 4
establish the socket using connect at the client and
accept at the server.
connect call starts( known as the three-way
handshake) to setting up a connection between the
client and server.
At the server, the accept call creates a new server-side
client socket.
After accept finishes, a new socket connection exists
between the client and server, data flow can occur.
Step 5
Client/server symmetry in Sockets applications.
Finally, you can break the connection between the
client and server using the close call.
Each
hardware
manufacturer can develop
its
own
hardware
architecture, it becomes
necessary to define a
standard
data
representation for data.
Little Endian format, which
means the lowest memory
address contains the lowest
order byte of the integer
(remember that addresses
are 32-bit integers).
Big Endian format, where
the lowest memory address
holds the highest order
byte of the integer.
10