Your SlideShare is downloading. ×
0
SOCKET
PROGRAMMING
Presented
By :

Divya Sharma
Overview
 What are sockets ?
 What is file descriptor ?
 Protocols
 Client – Server paradigm
 Socket API
 TCP(Transm...
What are Sockets ?
• A socket is defined as an endpoint of
communication
• Service access point of TCP/IP protocol stack
•...
What is file descriptor ?
Text Terminal
#x sock

Keyboard

#std
in

s td
#1

Display

ut
o

Program

Internet

#2stden

• ...
A socket is a file descriptor that lets an application read/write from/to the
network
int fd; /*socket descriptor*/
if ((f...
Protocols
• A protocol is a set of rules of communication. Protocols
are the building blocks of a network architecture.
• ...
Client - Server paradigm
• Server waits for client to request a connection.
• Client contacts server to establish a connec...
Socket API
Server and client exchange messages over the network through a common
Socket API
CLIENTS
User
space

SERVER
POR...
Transmission Control Protocol (TCP)
TCP

Telephone call

• Reliable - guarantee delivery

•

Guaranteed delivery

• Byte s...
Review: TCP Client - server interaction
TCP Server

socket( )
bind( )
TCP Client

listen( )

socket( )
connect( )
write( )...
User Datagram Protocol (UDP)
UDP
•
•
•
•
•

Post Mail

Single socket to receive
messages
No guarantee of delivery
Not nece...
Review: UDP Client – server interaction
UDP Server
socket( )
UDP client
bind( )

socket( )
sendto( )

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

One - to - one
Connection - oriented
Reliable
In order delive...
Final thoughts
• Make sure to #include the header files
that defines used functions
• Check man – pages and web – site
for...
Thank You
Upcoming SlideShare
Loading in...5
×

Socket programming

526

Published on

Published in: Education, Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
526
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
6
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • <number>
  • Transcript of "Socket programming"

    1. 1. SOCKET PROGRAMMING Presented By : Divya Sharma
    2. 2. Overview  What are sockets ?  What is file descriptor ?  Protocols  Client – Server paradigm  Socket API  TCP(Transmission Control Protocol)  UDP(User Datagram Protocol)
    3. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 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. 14. Final thoughts • Make sure to #include the header files that defines used functions • Check man – pages and web – site for additional information
    15. 15. Thank You
    1. A particular slide catching your eye?

      Clipping is a handy way to collect important slides you want to go back to later.

    ×