Professional Documents
Culture Documents
Jan 2005
Why do we need sockets?
Provides an abstraction for
interprocess communication
• A socket is one endpoint of a two-way
communication link between two programs
running on the network.
• A socket is bound to a port number so that the
TCP layer can identify the application that data
is destined to be sent to.
• An endpoint is a combination of an IP address
and a port number.
• a port (noun) is a "logical connection place“
• When referring to a network or to the Internet,
a software or network port is a location where
Functions
–Define an “end- point” for
communication
–Initiate and accept a connection
–Send and receive data
–Terminate a connection gracefully
Examples
Client Server
Addresses, Ports and Sockets
• Like apartments and mailboxes
– You are the application
– Your apartment building address is the address
– Your mailbox is the port
– The post-office is the network
– The socket is the key that gives you access to the
right mailbox
Client – high level view
Create a socket
Read/write data
Shutdown connection
Server – high level view
Create a socket
Shutdown connection
socket() TCP Server
bind() Well-known port
Socket() accept()
blocks until connection from client
connect() Connection establishment
write()
read()
process request
write()
read()
close()
read()
close()