SlideShare a Scribd company logo
1 of 15
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

What's hot

A Short Java Socket Tutorial
A Short Java Socket TutorialA Short Java Socket Tutorial
A Short Java Socket Tutorial
Guo Albert
 
Socket Programming using Java
Socket Programming using JavaSocket Programming using Java
Socket Programming using Java
Rahul Hada
 

What's hot (20)

Part 6 : Internet applications
Part 6 : Internet applicationsPart 6 : Internet applications
Part 6 : Internet applications
 
Socket Programming
Socket ProgrammingSocket Programming
Socket Programming
 
Socket programming
Socket programmingSocket programming
Socket programming
 
Socket programming
Socket programmingSocket programming
Socket programming
 
A Short Java Socket Tutorial
A Short Java Socket TutorialA Short Java Socket Tutorial
A Short Java Socket Tutorial
 
Socket programming in C#
Socket programming in C#Socket programming in C#
Socket programming in C#
 
Network Socket Programming with JAVA
Network Socket Programming with JAVANetwork Socket Programming with JAVA
Network Socket Programming with JAVA
 
Networking and socket
Networking and socketNetworking and socket
Networking and socket
 
Ports & sockets
Ports  & sockets Ports  & sockets
Ports & sockets
 
Socket Programming using Java
Socket Programming using JavaSocket Programming using Java
Socket Programming using Java
 
Networking in python by Rj
Networking in python by RjNetworking in python by Rj
Networking in python by Rj
 
Java Socket Programming
Java Socket ProgrammingJava Socket Programming
Java Socket Programming
 
Sockets in unix
Sockets in unixSockets in unix
Sockets in unix
 
Chapter 3 : User Datagram Protocol (UDP)
Chapter 3 : User Datagram Protocol (UDP)Chapter 3 : User Datagram Protocol (UDP)
Chapter 3 : User Datagram Protocol (UDP)
 
TCP/IP(networking)
TCP/IP(networking)TCP/IP(networking)
TCP/IP(networking)
 
Network protocols and Java programming
Network protocols and Java programmingNetwork protocols and Java programming
Network protocols and Java programming
 
TCPLS presentation @ietf 109
TCPLS presentation @ietf 109TCPLS presentation @ietf 109
TCPLS presentation @ietf 109
 
Remote Login and File Transfer Protocols
Remote Login and File Transfer ProtocolsRemote Login and File Transfer Protocols
Remote Login and File Transfer Protocols
 
Transport layer interface
Transport layer interface Transport layer interface
Transport layer interface
 
Chap 1 Network Theory & Java Overview
Chap 1   Network Theory & Java OverviewChap 1   Network Theory & Java Overview
Chap 1 Network Theory & Java Overview
 

Viewers also liked (8)

Socket Programming
Socket ProgrammingSocket Programming
Socket Programming
 
Socket Programming- Data Link Access
Socket Programming- Data Link AccessSocket Programming- Data Link Access
Socket Programming- Data Link Access
 
Socket programming, and openresty
Socket programming, and openrestySocket programming, and openresty
Socket programming, and openresty
 
Socket Programming
Socket ProgrammingSocket Programming
Socket Programming
 
Socket programming
Socket programmingSocket programming
Socket programming
 
Networking Java Socket Programming
Networking Java Socket ProgrammingNetworking Java Socket Programming
Networking Java Socket Programming
 
Network programming in java - PPT
Network programming in java - PPTNetwork programming in java - PPT
Network programming in java - PPT
 
Ppt of socket
Ppt of socketPpt of socket
Ppt of socket
 

Similar to Socket programming

Application Layer and Socket Programming
Application Layer and Socket ProgrammingApplication Layer and Socket Programming
Application Layer and Socket Programming
elliando dias
 
Socket programming in C
Socket programming in CSocket programming in C
Socket programming in C
Deepak Swain
 

Similar to Socket programming (20)

Application Layer and Socket Programming
Application Layer and Socket ProgrammingApplication Layer and Socket Programming
Application Layer and Socket Programming
 
Lecture set 7
Lecture set 7Lecture set 7
Lecture set 7
 
Byte Ordering - Unit 2.pptx
Byte Ordering - Unit 2.pptxByte Ordering - Unit 2.pptx
Byte Ordering - Unit 2.pptx
 
Network programming in Java
Network programming in JavaNetwork programming in Java
Network programming in Java
 
Datacom_Section_2_-_Protocols.ppt
Datacom_Section_2_-_Protocols.pptDatacom_Section_2_-_Protocols.ppt
Datacom_Section_2_-_Protocols.ppt
 
Networking
NetworkingNetworking
Networking
 
CCNA (R & S) Module 01 - Introduction to Networks - Chapter 9
CCNA (R & S) Module 01 - Introduction to Networks - Chapter 9CCNA (R & S) Module 01 - Introduction to Networks - Chapter 9
CCNA (R & S) Module 01 - Introduction to Networks - Chapter 9
 
Network programming in Java
Network programming in JavaNetwork programming in Java
Network programming in Java
 
Java_Socket_Programming (2).ppt
Java_Socket_Programming (2).pptJava_Socket_Programming (2).ppt
Java_Socket_Programming (2).ppt
 
PYTHON -Chapter 5 NETWORK - MAULIK BORSANIYA
PYTHON -Chapter 5 NETWORK - MAULIK BORSANIYAPYTHON -Chapter 5 NETWORK - MAULIK BORSANIYA
PYTHON -Chapter 5 NETWORK - MAULIK BORSANIYA
 
28 networking
28  networking28  networking
28 networking
 
Network Programming in Java
Network Programming in JavaNetwork Programming in Java
Network Programming in Java
 
Transport layer protocol
Transport layer protocolTransport layer protocol
Transport layer protocol
 
Application Layer and Protocols
Application Layer and ProtocolsApplication Layer and Protocols
Application Layer and Protocols
 
Aplication and Transport layer- a practical approach
Aplication and Transport layer-  a practical approachAplication and Transport layer-  a practical approach
Aplication and Transport layer- a practical approach
 
+ Network Programming.pdf
+ Network Programming.pdf+ Network Programming.pdf
+ Network Programming.pdf
 
Socket programming in C
Socket programming in CSocket programming in C
Socket programming in C
 
Part 7 : HTTP/2, UDP and TCP
Part 7 : HTTP/2, UDP and TCPPart 7 : HTTP/2, UDP and TCP
Part 7 : HTTP/2, UDP and TCP
 
Network Programming-Python-13-8-2023.pptx
Network Programming-Python-13-8-2023.pptxNetwork Programming-Python-13-8-2023.pptx
Network Programming-Python-13-8-2023.pptx
 
09 Systems Software Programming-Network Programming.pptx
09 Systems Software Programming-Network Programming.pptx09 Systems Software Programming-Network Programming.pptx
09 Systems Software Programming-Network Programming.pptx
 

Recently uploaded

Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
kauryashika82
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
negromaestrong
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
ZurliaSoop
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
AnaAcapella
 

Recently uploaded (20)

This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Magic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptxMagic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptx
 
Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Seal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptxSeal of Good Local Governance (SGLG) 2024Final.pptx
Seal of Good Local Governance (SGLG) 2024Final.pptx
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
Jual Obat Aborsi Hongkong ( Asli No.1 ) 085657271886 Obat Penggugur Kandungan...
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
psychiatric nursing HISTORY COLLECTION .docx
psychiatric  nursing HISTORY  COLLECTION  .docxpsychiatric  nursing HISTORY  COLLECTION  .docx
psychiatric nursing HISTORY COLLECTION .docx
 
ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701ComPTIA Overview | Comptia Security+ Book SY0-701
ComPTIA Overview | Comptia Security+ Book SY0-701
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 

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

  1. &lt;number&gt;