0% found this document useful (0 votes)
81 views11 pages

Linux Sockets

Sockets provide an abstraction for interprocess communication over a network. A socket is bound to a port number so that data knows which application it is destined for. There are two main types of sockets: stream sockets which provide reliable connected service using TCP and datagram sockets which provide unreliable best-effort service using UDP. Sockets define endpoints for communication, allow initiating and accepting connections, and sending and receiving data. Common applications that use sockets include file transfer, web browsers, email, and audio/video streaming.

Uploaded by

prakash
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
81 views11 pages

Linux Sockets

Sockets provide an abstraction for interprocess communication over a network. A socket is bound to a port number so that data knows which application it is destined for. There are two main types of sockets: stream sockets which provide reliable connected service using TCP and datagram sockets which provide unreliable best-effort service using UDP. Sockets define endpoints for communication, allow initiating and accepting connections, and sending and receiving data. Common applications that use sockets include file transfer, web browsers, email, and audio/video streaming.

Uploaded by

prakash
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 11

Introduction to Sockets

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

File transfer apps (FTP), Web browsers


(HTTP), Email (SMTP/ POP3), etc…
Types of Sockets
• Two different types of sockets :
– stream vs. datagram

• Stream socket :( a. k. a. connection- oriented socket)


– It provides reliable, connected networking service
– Error free; no out- of- order packets (uses TCP)
– applications: telnet/ ssh, http, …

• Datagram socket :( a. k. a. connectionless socket)


– It provides unreliable, best- effort networking service
– Packets may be lost; may arrive out of order (uses UDP)
– applications: streaming audio/ video (realplayer), …
Addressing

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

Setup the server address

Connect to the server

Read/write data

Shutdown connection
Server – high level view
Create a socket

Bind the socket

Listen for connections

Accept new client connections

Read/write to client connections

Shutdown connection
socket() TCP Server
bind() Well-known port

TCP Client listen()

Socket() accept()
blocks until connection from client
connect() Connection establishment

write()
read()

process request

write()
read()

close()
read()

close()

You might also like