SlideShare a Scribd company logo
SOCKET
PROGRAMMING
Presented
By :

Divya Sharma
Overview
 What are sockets ?
 What is file descriptor ?
 Protocols
 Client – Server paradigm
 Socket API
 TCP(Transmission Control Protocol)
 UDP(User Datagram Protocol)
What are Sockets ?
• A socket is defined as an endpoint of
communication
• Service access point of TCP/IP protocol stack
• between Application layer and Transport layer

• A file descriptor that lets an application read/write
data from/to the network
• Once configured the application can
• Send data to the socket
• Receive data from the socket
What is file descriptor ?
Text Terminal
#x sock

Keyboard

#std
in

s td
#1

Display

ut
o

Program

Internet

#2stden

• E.g. cout writes data to stdout #(1)
cin read data from stdin #(0)
A socket is a file descriptor that lets an application read/write from/to the
network
int fd; /*socket descriptor*/
if ((fd = socket(AF_INET, SOCK-STREAM, 0)) < 0) }
fd = socket(AF_INET,
SOCK_STREAM, 0)) < 0) }
perror(“socket”);
exit(1);
• socket returns an integer(socket descriptor)
• fd < 0} indicates that an error occurred
• Socket descriptor s are similar to file descriptors
• AF_INET: associates a socket with the internet protocol family
• SOCK_STREAM: selects the TCP protocol
• SOCK_DGRAM: selects the UDP protocol
Protocols
• A protocol is a set of rules of communication. Protocols
are the building blocks of a network architecture.
• Each protocol object has two different interfaces:
 service interface: operations on this protocol
 peer-to-peer interface: messages exchanged with
peer
• Term “protocol” is overloaded
 specification of peer-to-peer interface
 module that implements this interface
Client - Server paradigm
• Server waits for client to request a connection.
• Client contacts server to establish a connection.
• Client sends request.
• Server sends reply.
• Client and/or server terminate connection.
Socket API
Server and client exchange messages over the network through a common
Socket API
CLIENTS
User
space

SERVER
PORTS

TCP/UDP

TCP/UDP
IP
Ethernet
Adapter

SOCKET
API

IP
Ethernet
Adapter

Kernel
space

Hardw
-are
Transmission Control Protocol (TCP)
TCP

Telephone call

• Reliable - guarantee delivery

•

Guaranteed delivery

• Byte stream - in - order
delivery

•

In order delivery

•

Connection oriented

•

Setup connection followed
by conversation

• Connection - oriented single socket per connection
• Setup connection followed
by data transfer

Example TCP applications
Web, E-mail, Telnet
Review: TCP Client - server interaction
TCP Server

socket( )
bind( )
TCP Client

listen( )

socket( )
connect( )
write( )

Connection establishment

Data request

accept( )

read( )
Data reply

write( )

read( )
close( )

end – of - f
ile

read()
notification

close()
User Datagram Protocol (UDP)
UDP
•
•
•
•
•

Post Mail

Single socket to receive
messages
No guarantee of delivery
Not necessarily in – order
delivery
Datagram - independent
packets
Must address each packet

•
•
•
•
•

Single mail box to
receive letters
Unreliable
Not necessarily in order delivery
Letters send
independently
Must address each reply

Example UDP applications
Multimedia, voice over IP
Review: UDP Client – server interaction
UDP Server
socket( )
UDP client
bind( )

socket( )
sendto( )

recvfrom( )
close( )

data

requ
est

data reply

recvfrom( )
blocks until datagram
received from a client

sendto()
close( )
TCP vs. UDP
• Transmission Control Protocol (TCP)
•
•
•
•
•

One - to - one
Connection - oriented
Reliable
In order delivery
Transmission after connect

• User Datagram Protocol (UDP)
•
•
•
•
•

One to one or many
Connectionless
Unreliable
Unordered delivery
Transmission with destination address
Final thoughts
• Make sure to #include the header files
that defines used functions
• Check man – pages and web – site
for additional information
Thank You

More Related Content

PPT
Socket Programming
PPT
Sockets
PPTX
Socket网络编程
PPTX
Python Sockets
PDF
Socket programming using C
PPTX
Socket programming or network programming
PDF
Socket programming using java
PPTX
Client server examples for tcp abnormal conditions
Socket Programming
Sockets
Socket网络编程
Python Sockets
Socket programming using C
Socket programming or network programming
Socket programming using java
Client server examples for tcp abnormal conditions

What's hot (20)

PPTX
Part 6 : Internet applications
PPTX
Socket Programming
PPT
Socket programming
PPTX
Socket programming
PPT
A Short Java Socket Tutorial
PPTX
Socket programming in C#
PPTX
Network Socket Programming with JAVA
PPT
Networking and socket
PPT
Ports & sockets
PDF
Socket Programming using Java
PPTX
PPT
Java Socket Programming
PPT
Sockets in unix
PDF
Chapter 3 : User Datagram Protocol (UDP)
PPT
TCP/IP(networking)
PPSX
Network protocols and Java programming
PPTX
TCPLS presentation @ietf 109
PPTX
Remote Login and File Transfer Protocols
PPTX
Transport layer interface
PDF
Chap 1 Network Theory & Java Overview
Part 6 : Internet applications
Socket Programming
Socket programming
Socket programming
A Short Java Socket Tutorial
Socket programming in C#
Network Socket Programming with JAVA
Networking and socket
Ports & sockets
Socket Programming using Java
Java Socket Programming
Sockets in unix
Chapter 3 : User Datagram Protocol (UDP)
TCP/IP(networking)
Network protocols and Java programming
TCPLS presentation @ietf 109
Remote Login and File Transfer Protocols
Transport layer interface
Chap 1 Network Theory & Java Overview
Ad

Viewers also liked (8)

PPT
Socket Programming
PDF
Socket Programming- Data Link Access
PDF
Socket programming, and openresty
PDF
Socket Programming
PPTX
Socket programming
PPT
Networking Java Socket Programming
PPTX
Network programming in java - PPT
PPT
Ppt of socket
Socket Programming
Socket Programming- Data Link Access
Socket programming, and openresty
Socket Programming
Socket programming
Networking Java Socket Programming
Network programming in java - PPT
Ppt of socket
Ad

Similar to Socket programming (20)

PPT
Application Layer and Socket Programming
PPT
lecture03for socket programming college.ppt
PPT
lecture03 on socket programming000000.ppt
PDF
Lecture set 7
PPTX
Byte Ordering - Unit 2.pptx
PPT
Network programming in Java
PPT
Datacom_Section_2_-_Protocols.ppt
PPT
Networking
PPTX
ITN6_Instructor_Materials_Chapter9git.pptx
PPTX
CCNA (R & S) Module 01 - Introduction to Networks - Chapter 9
PPT
Network programming in Java
PPTX
PYTHON -Chapter 5 NETWORK - MAULIK BORSANIYA
PDF
28 networking
PPT
Network Programming in Java
PPTX
Transport layer protocol
PPTX
Application Layer and Protocols
PDF
Aplication and Transport layer- a practical approach
PDF
JavaSockets-Session10 New York university.pdf
PDF
sockets SMTP Bmsce ppt information science and engineering
PDF
+ Network Programming.pdf
Application Layer and Socket Programming
lecture03for socket programming college.ppt
lecture03 on socket programming000000.ppt
Lecture set 7
Byte Ordering - Unit 2.pptx
Network programming in Java
Datacom_Section_2_-_Protocols.ppt
Networking
ITN6_Instructor_Materials_Chapter9git.pptx
CCNA (R & S) Module 01 - Introduction to Networks - Chapter 9
Network programming in Java
PYTHON -Chapter 5 NETWORK - MAULIK BORSANIYA
28 networking
Network Programming in Java
Transport layer protocol
Application Layer and Protocols
Aplication and Transport layer- a practical approach
JavaSockets-Session10 New York university.pdf
sockets SMTP Bmsce ppt information science and engineering
+ Network Programming.pdf

Recently uploaded (20)

PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PPTX
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
PDF
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PPTX
GDM (1) (1).pptx small presentation for students
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
01-Introduction-to-Information-Management.pdf
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
A systematic review of self-coping strategies used by university students to ...
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
PPTX
Cell Structure & Organelles in detailed.
PPTX
Cell Types and Its function , kingdom of life
PDF
Computing-Curriculum for Schools in Ghana
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
Final Presentation General Medicine 03-08-2024.pptx
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
A GUIDE TO GENETICS FOR UNDERGRADUATE MEDICAL STUDENTS
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
202450812 BayCHI UCSC-SV 20250812 v17.pptx
O5-L3 Freight Transport Ops (International) V1.pdf
GDM (1) (1).pptx small presentation for students
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
01-Introduction-to-Information-Management.pdf
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
A systematic review of self-coping strategies used by university students to ...
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
Cell Structure & Organelles in detailed.
Cell Types and Its function , kingdom of life
Computing-Curriculum for Schools in Ghana

Socket programming

  • 2. Overview  What are sockets ?  What is file descriptor ?  Protocols  Client – Server paradigm  Socket API  TCP(Transmission Control Protocol)  UDP(User Datagram Protocol)
  • 3. What are Sockets ? • A socket is defined as an endpoint of communication • Service access point of TCP/IP protocol stack • between Application layer and Transport layer • A file descriptor that lets an application read/write data from/to the network • Once configured the application can • Send data to the socket • Receive data from the socket
  • 4. What is file descriptor ? Text Terminal #x sock Keyboard #std in s td #1 Display ut o Program Internet #2stden • E.g. cout writes data to stdout #(1) cin read data from stdin #(0)
  • 5. A socket is a file descriptor that lets an application read/write from/to the network int fd; /*socket descriptor*/ if ((fd = socket(AF_INET, SOCK-STREAM, 0)) < 0) } fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) } perror(“socket”); exit(1); • socket returns an integer(socket descriptor) • fd < 0} indicates that an error occurred • Socket descriptor s are similar to file descriptors • AF_INET: associates a socket with the internet protocol family • SOCK_STREAM: selects the TCP protocol • SOCK_DGRAM: selects the UDP protocol
  • 6. Protocols • A protocol is a set of rules of communication. Protocols are the building blocks of a network architecture. • Each protocol object has two different interfaces:  service interface: operations on this protocol  peer-to-peer interface: messages exchanged with peer • Term “protocol” is overloaded  specification of peer-to-peer interface  module that implements this interface
  • 7. Client - Server paradigm • Server waits for client to request a connection. • Client contacts server to establish a connection. • Client sends request. • Server sends reply. • Client and/or server terminate connection.
  • 8. Socket API Server and client exchange messages over the network through a common Socket API CLIENTS User space SERVER PORTS TCP/UDP TCP/UDP IP Ethernet Adapter SOCKET API IP Ethernet Adapter Kernel space Hardw -are
  • 9. Transmission Control Protocol (TCP) TCP Telephone call • Reliable - guarantee delivery • Guaranteed delivery • Byte stream - in - order delivery • In order delivery • Connection oriented • Setup connection followed by conversation • Connection - oriented single socket per connection • Setup connection followed by data transfer Example TCP applications Web, E-mail, Telnet
  • 10. Review: TCP Client - server interaction TCP Server socket( ) bind( ) TCP Client listen( ) socket( ) connect( ) write( ) Connection establishment Data request accept( ) read( ) Data reply write( ) read( ) close( ) end – of - f ile read() notification close()
  • 11. User Datagram Protocol (UDP) UDP • • • • • Post Mail Single socket to receive messages No guarantee of delivery Not necessarily in – order delivery Datagram - independent packets Must address each packet • • • • • Single mail box to receive letters Unreliable Not necessarily in order delivery Letters send independently Must address each reply Example UDP applications Multimedia, voice over IP
  • 12. Review: UDP Client – server interaction UDP Server socket( ) UDP client bind( ) socket( ) sendto( ) recvfrom( ) close( ) data requ est data reply recvfrom( ) blocks until datagram received from a client sendto() close( )
  • 13. TCP vs. UDP • Transmission Control Protocol (TCP) • • • • • One - to - one Connection - oriented Reliable In order delivery Transmission after connect • User Datagram Protocol (UDP) • • • • • One to one or many Connectionless Unreliable Unordered delivery Transmission with destination address
  • 14. Final thoughts • Make sure to #include the header files that defines used functions • Check man – pages and web – site for additional information

Editor's Notes

  • #12: &lt;number&gt;