SlideShare ist ein Scribd-Unternehmen logo
1 von 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

Weitere ähnliche Inhalte

Was ist angesagt?

Socket programming
Socket programmingSocket programming
Socket programmingharsh_bca06
 
Socket programming
Socket programmingSocket programming
Socket programmingUjjwal 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 JAVADudy Ali
 
Networking and socket
Networking and socketNetworking and socket
Networking and socketsrmubca
 
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
 
Java Socket Programming
Java Socket ProgrammingJava Socket Programming
Java Socket ProgrammingVipin Yadav
 
Sockets in unix
Sockets in unixSockets in unix
Sockets in unixswtjerin4u
 
Network protocols and Java programming
Network protocols and Java programmingNetwork protocols and Java programming
Network protocols and Java programmingdifatta
 
Remote Login and File Transfer Protocols
Remote Login and File Transfer ProtocolsRemote Login and File Transfer Protocols
Remote Login and File Transfer ProtocolsHimanshu Pathak
 
Transport layer interface
Transport layer interface Transport layer interface
Transport layer interface CEC Landran
 

Was ist angesagt? (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
 

Andere mochten auch

Socket Programming
Socket ProgrammingSocket Programming
Socket ProgrammingMostak Ahmed
 
Socket Programming- Data Link Access
Socket Programming- Data Link AccessSocket Programming- Data Link Access
Socket Programming- Data Link AccessLJ PROJECTS
 
Socket programming, and openresty
Socket programming, and openrestySocket programming, and openresty
Socket programming, and openrestyTavish Naruka
 
Socket programming
Socket programmingSocket programming
Socket programmingAnurag 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 - PPTkamal kotecha
 

Andere mochten auch (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
 

Ähnlich wie 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.pptxRockyBhai46825
 
Network programming in Java
Network programming in JavaNetwork programming in Java
Network programming in JavaTushar B Kute
 
Datacom_Section_2_-_Protocols.ppt
Datacom_Section_2_-_Protocols.pptDatacom_Section_2_-_Protocols.ppt
Datacom_Section_2_-_Protocols.pptKristopher 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 9Waqas Ahmed Nawaz
 
Network programming in Java
Network programming in JavaNetwork programming in Java
Network programming in JavaTushar B Kute
 
Java_Socket_Programming (2).ppt
Java_Socket_Programming (2).pptJava_Socket_Programming (2).ppt
Java_Socket_Programming (2).pptssuserec53e73
 
PYTHON -Chapter 5 NETWORK - MAULIK BORSANIYA
PYTHON -Chapter 5 NETWORK - MAULIK BORSANIYAPYTHON -Chapter 5 NETWORK - MAULIK BORSANIYA
PYTHON -Chapter 5 NETWORK - MAULIK BORSANIYAMaulik Borsaniya
 
Network Programming in Java
Network Programming in JavaNetwork Programming in Java
Network Programming in JavaTushar B Kute
 
Application Layer and Protocols
Application Layer and ProtocolsApplication Layer and Protocols
Application Layer and ProtocolsRubal 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 approachSarah R. Dowlath
 
+ Network Programming.pdf
+ Network Programming.pdf+ Network Programming.pdf
+ Network Programming.pdfOluwafolakeOjo
 
Socket programming in C
Socket programming in CSocket programming in C
Socket programming in CDeepak Swain
 
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.pptxssuser23035c
 
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.pptxKushalSrivastava23
 

Ähnlich wie 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
 

Kürzlich hochgeladen

Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024Janet Corral
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfchloefrazer622
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpinRaunakKeshri1
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
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 Delhikauryashika82
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...Sapna Thakur
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfJayanti Pande
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 

Kürzlich hochgeladen (20)

Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
General AI for Medical Educators April 2024
General AI for Medical Educators April 2024General AI for Medical Educators April 2024
General AI for Medical Educators April 2024
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Disha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdfDisha NEET Physics Guide for classes 11 and 12.pdf
Disha NEET Physics Guide for classes 11 and 12.pdf
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Student login on Anyboli platform.helpin
Student login on Anyboli platform.helpinStudent login on Anyboli platform.helpin
Student login on Anyboli platform.helpin
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
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
 
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
BAG TECHNIQUE Bag technique-a tool making use of public health bag through wh...
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Web & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdfWeb & Social Media Analytics Previous Year Question Paper.pdf
Web & Social Media Analytics Previous Year Question Paper.pdf
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 

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

Hinweis der Redaktion

  1. &lt;number&gt;