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

What's hot

Part 6 : Internet applications
Part 6 : Internet applicationsPart 6 : Internet applications
Part 6 : Internet applications
Olivier Bonaventure
 
Socket programming
Socket programmingSocket programming
Socket programming
harsh_bca06
 
Socket programming
Socket programmingSocket programming
Socket programming
Ujjwal Kumar
 
A Short Java Socket Tutorial
A Short Java Socket TutorialA Short Java Socket Tutorial
A Short Java Socket TutorialGuo Albert
 
Socket programming in C#
Socket programming in C#Socket programming in C#
Socket programming in C#
Nang Luc Vu
 
Network Socket Programming with JAVA
Network Socket Programming with JAVANetwork Socket Programming with JAVA
Network Socket Programming with JAVA
Dudy Ali
 
Networking and socket
Networking and socketNetworking and socket
Networking and socket
srmubca
 
Ports & sockets
Ports  & sockets Ports  & sockets
Ports & sockets
myrajendra
 
Socket Programming using Java
Socket Programming using JavaSocket Programming using Java
Socket Programming using JavaRahul Hada
 
Networking in python by Rj
Networking in python by RjNetworking in python by Rj
Java Socket Programming
Java Socket ProgrammingJava Socket Programming
Java Socket Programming
Vipin Yadav
 
Sockets in unix
Sockets in unixSockets in unix
Sockets in unix
swtjerin4u
 
Chapter 3 : User Datagram Protocol (UDP)
Chapter 3 : User Datagram Protocol (UDP)Chapter 3 : User Datagram Protocol (UDP)
Chapter 3 : User Datagram Protocol (UDP)
Ministry of Higher Education
 
Network protocols and Java programming
Network protocols and Java programmingNetwork protocols and Java programming
Network protocols and Java programming
difatta
 
TCPLS presentation @ietf 109
TCPLS presentation @ietf 109TCPLS presentation @ietf 109
TCPLS presentation @ietf 109
Olivier Bonaventure
 
Remote Login and File Transfer Protocols
Remote Login and File Transfer ProtocolsRemote Login and File Transfer Protocols
Remote Login and File Transfer Protocols
Himanshu Pathak
 
Transport layer interface
Transport layer interface Transport layer interface
Transport layer interface
CEC Landran
 
Chap 1 Network Theory & Java Overview
Chap 1   Network Theory & Java OverviewChap 1   Network Theory & Java Overview
Chap 1 Network Theory & Java Overview
Ministry of Higher Education
 

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

Socket Programming
Socket ProgrammingSocket Programming
Socket Programming
Mostak Ahmed
 
Socket Programming- Data Link Access
Socket Programming- Data Link AccessSocket Programming- Data Link Access
Socket Programming- Data Link Access
LJ PROJECTS
 
Socket programming, and openresty
Socket programming, and openrestySocket programming, and openresty
Socket programming, and openresty
Tavish Naruka
 
Socket programming
Socket programmingSocket programming
Socket programming
Anurag Tomar
 
Networking Java Socket Programming
Networking Java Socket ProgrammingNetworking Java Socket Programming
Networking Java Socket ProgrammingMousmi Pawar
 
Network programming in java - PPT
Network programming in java - PPTNetwork programming in java - PPT
Network programming in java - PPT
kamal kotecha
 

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 Programmingelliando dias
 
Byte Ordering - Unit 2.pptx
Byte Ordering - Unit 2.pptxByte Ordering - Unit 2.pptx
Byte Ordering - Unit 2.pptx
RockyBhai46825
 
Network programming in Java
Network programming in JavaNetwork programming in Java
Network programming in Java
Tushar B Kute
 
Datacom_Section_2_-_Protocols.ppt
Datacom_Section_2_-_Protocols.pptDatacom_Section_2_-_Protocols.ppt
Datacom_Section_2_-_Protocols.ppt
Kristopher Hefner
 
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
Waqas Ahmed Nawaz
 
Network programming in Java
Network programming in JavaNetwork programming in Java
Network programming in Java
Tushar B Kute
 
Java_Socket_Programming (2).ppt
Java_Socket_Programming (2).pptJava_Socket_Programming (2).ppt
Java_Socket_Programming (2).ppt
ssuserec53e73
 
PYTHON -Chapter 5 NETWORK - MAULIK BORSANIYA
PYTHON -Chapter 5 NETWORK - MAULIK BORSANIYAPYTHON -Chapter 5 NETWORK - MAULIK BORSANIYA
PYTHON -Chapter 5 NETWORK - MAULIK BORSANIYA
Maulik Borsaniya
 
Network Programming in Java
Network Programming in JavaNetwork Programming in Java
Network Programming in Java
Tushar B Kute
 
Transport layer protocol
Transport layer protocolTransport layer protocol
Transport layer protocol
N.Jagadish Kumar
 
Application Layer and Protocols
Application Layer and ProtocolsApplication Layer and Protocols
Application Layer and Protocols
Rubal Sagwal
 
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
Sarah R. Dowlath
 
+ Network Programming.pdf
+ Network Programming.pdf+ Network Programming.pdf
+ Network Programming.pdf
OluwafolakeOjo
 
Socket programming in C
Socket programming in CSocket programming in C
Socket programming in CDeepak Swain
 
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
Olivier Bonaventure
 
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
ssuser23035c
 
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
KushalSrivastava23
 

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

1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
Multithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race conditionMultithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race condition
Mohammed Sikander
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
SACHIN R KONDAGURI
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
EverAndrsGuerraGuerr
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
deeptiverma2406
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
Digital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion DesignsDigital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion Designs
chanes7
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
Special education needs
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
DeeptiGupta154
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 

Recently uploaded (20)

1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
Multithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race conditionMultithreading_in_C++ - std::thread, race condition
Multithreading_in_C++ - std::thread, race condition
 
The approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
"Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe..."Protectable subject matters, Protection in biotechnology, Protection of othe...
"Protectable subject matters, Protection in biotechnology, Protection of othe...
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
Thesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.pptThesis Statement for students diagnonsed withADHD.ppt
Thesis Statement for students diagnonsed withADHD.ppt
 
Best Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDABest Digital Marketing Institute In NOIDA
Best Digital Marketing Institute In NOIDA
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
Digital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion DesignsDigital Artifact 2 - Investigating Pavilion Designs
Digital Artifact 2 - Investigating Pavilion Designs
 
special B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdfspecial B.ed 2nd year old paper_20240531.pdf
special B.ed 2nd year old paper_20240531.pdf
 
Overview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with MechanismOverview on Edible Vaccine: Pros & Cons with Mechanism
Overview on Edible Vaccine: Pros & Cons with Mechanism
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 

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;