Chapter 2 Applications and Layered Architectures Protocols, - - PowerPoint PPT Presentation
Chapter 2 Applications and Layered Architectures Protocols, - - PowerPoint PPT Presentation
Chapter 2 Applications and Layered Architectures Protocols, Services & Layering Layers, Services & Protocols l The overall communications process between two or more machines connected across one or more networks is very complex l
Layers, Services & Protocols
l The overall communications process
between two or more machines connected across one or more networks is very complex
l Layering partitions related communications
functions into groups that are manageable
l Each layer provides a service to the layer
above
l Each layer operates according to a protocol
Layer
l A set of related communication functions that can be
managed and grouped together Examples of Layers
l Application Layer: communications functions that
are used by application programs
l HTTP (Browsing), DNS (URL to IP address), SMTP (email)
l Transport Layer: end-to-end communications
between two processes in two machines
l TCP Reliable Stream Service, UDP Datagram Service
l Network Layer: communications between machines
l Internet Protocol (IP) best effort service
Protocols
l A protocol is a set of rules that governs how
two or more communicating entities in a layer are to interact
l Messages that can be sent and received l Actions that are to be taken when a certain
event occurs, e.g. sending or receiving messages, expiry of timers
l The purpose of a protocol is to provide a
service to the layer above
Example: HTTP
l HTTP is an application layer protocol l Retrieves documents on behalf of a browser
application program
l HTTP specifies fields in request messages
and response messages
l Request types; Response codes l Content type, options, cookies, …
l HTTP specifies actions to be taken upon
receipt of certain messages
HTTP Client
HTTP Protocol
GET Response
HTTP Server
l HTTP provides service to a browsing application l HTTP messages exchanged between HTTP client
and HTTP server
l HTTP client and server are processes running in two
different machines across the Internet
l HTTP uses the reliable stream transfer service
provided by TCP (Transmission Control Protocol)
HTTP server HTTP client
TCP Port 80 Port 1127
HTTP uses service of TCP
TCP
Response GET
TCP
80, 1127 GET 1127, 80 bytes Response
GET
Response
Example: TCP
l TCP is a transport layer protocol l Provides reliable byte stream service between two
processes in two computers across the Internet
l Sequence numbers keep track of the bytes that have
been transmitted and received
l Error detection and retransmission used to recover
from transmission errors, losses, duplications
l TCP is connection-oriented: the sender and receiver
must first establish an association and set initial sequence numbers before data is transferred
l Connection ID is specified uniquely by
(send port #, send IP address, receive port #, receiver IP address)
l HTTP server has well-known port # 80
Example: DNS Protocol
l DNS (Domain Name System) is an application
layer protocol
l DNS is a distributed database that resides in
multiple machines in the Internet
l DNS protocol allows queries of different types
l Name-to-address or Address-to-name l Mail exchange
l DNS usually involves short messages and so
uses service provided by UDP
l Well-known port 53
l Local Name Server: resolve frequently-used names
l University department, ISP l Contacts Root Name server if it cannot resolve query
l Root Name Servers: 13 globally (actually 100’s)
l Resolves query or refers query to Authoritative Name
Server
l Authoritative Name Server: last resort
l Every machine must register its address with at least two
authoritative name servers
1 2 3 4 5 6 Local Name Server Root Name Server Authoritative Name Server
Web Browsing Application
l World Wide Web allows users to access resources
(i.e. documents) located in computers connected to the Internet
l Documents prepared using HyperText Markup
Language (HTML)
l A browser application program is used to access the
web
l The browser displays HTML documents that include
links to other documents
l Each link references a Uniform Resource Locator
(URL) that gives the name of the machine and the location of the given document
l Lets see what happens when a user clicks on a link
l User clicks on http://www.nytimes.com/ l URL contains Internet name of machine
(www.nytimes.com), but not Internet address
l Internet needs Internet address to send packets to a
machine
l Browser software uses DNS protocol to send query
for Internet address
l DNS system responds with Internet address
- Q. www.nytimes.com?
- A. 64.15.247.200
- 1. DNS
l Browser uses HTTP to send request for document l HTTP server waits for requests by listening to a
well-known port number (80 for HTTP)
l HTTP client sends request messages through an
ephemeral port number, e.g. 1127
l HTTP needs a TCP connection between the HTTP
client and HTTP server to transfer messages reliably
TCP Connection Request From: 128.100.11.13 Port 1127 To: 64.15.247.200 Port 80
- 2. TCP
ACK, TCP Connection Request From: 64.15.247.200 Port 80 To:128.100.11.13 Port 1127 ACK
l HTTP client sends its request message: GET … l HTTP server sends a status response: 200 OK l HTTP server sends requested file l Browser displays document l Clicking a link sets off a chain of events across the
Internet!
l DNS, TCP, HTTP, Browser display
GET / HTTP/1.1 200 OK
- 3. HTTP
Content
Example: UDP
l UDP is a transport layer protocol l Provides best-effort datagram service
between two processes in two computers across the Internet
l Port numbers distinguish various processes
in the same machine
l UDP is connectionless l Datagram is sent immediately l Quick, simple, but not reliable l Used in DNS, real-time voice,…
Summary
l Layers: related communications functions
l Application Layer: HTTP, DNS l Transport Layer: TCP, UDP l Network Layer: IP
l Services: a protocol provides a communications
service to the layer above
l TCP provides connection-oriented reliable stream
service
l UDP provides connectionless datagram service
l Each layer builds on services of lower layers
l HTTP builds on top of TCP l DNS builds on top of UDP l TCP and UDP build on top of IP
Chapter 2 Applications and Layered Architectures
OSI Reference Model
OSI Reference Model
l A seven-layer abstract reference model for a
network architecture
l Provides a framework for the development of
protocols
l Unified view of layers, protocols, and services which
is used in the development of new protocols
l Detailed standards were developed for each layer,
but most of these are not in use
l TCP/IP protocols preempted deployment of OSI
protocols
7-Layer OSI Reference Model
Application Layer Presentation Layer Session Layer Transport Layer Network Layer Data Link Layer Physical Layer Application Layer Presentation Layer Session Layer Transport Layer Network Layer Data Link Layer Physical Layer Network Layer
Application Application
Data Link Layer Physical Layer Network Layer Data Link Layer Physical Layer
Communicating End Systems
One or More Network Nodes
End-to-End Protocols
Physical Layer
l Transfers bits across link l Definition & specification of the physical
aspects of a communications link
l Mechanical: cable, plugs, pins... l Electrical/optical: modulation, signal strength,
voltage levels, bit times, …
l functional/procedural: how to activate, maintain,
and deactivate physical links…
l Ethernet, DSL, cable modem, cell phone,… l Twisted-pair cable, coaxial cable optical fiber,
radio, infrared, …
Data Link Layer
l Transfers frames between directly connected machines l Groups bits into frames l Detection of bit errors; Retransmission of frames l Activation, maintenance, & deactivation of data link
connections
l Access control for local area networks (WIFI, Ethernet) l Flow control between machines of different speeds
Data Link Layer Physical Layer Data Link Layer Physical Layer
frames bits
Network Layer
l Transfers packets across multiple links and/or
multiple networks
l Addressing must scale to large networks l Nodes jointly execute routing algorithm to
determine paths across the network
l Forwarding transfers packet along hops in path l Congestion control to deal with traffic surges l Connection setup, maintenance, and teardown
when connection-based
Internetworking
l Internetworking is part of network layer and provides
transfer of packets across multiple possibly dissimilar networks
l Gateways (routers) direct packets across networks G = gateway H = host Net 1 Net 5 Net 3 Net 2
H
Net 3
G
H H H
G G G G G
Net 1 Net 2 Net 4 Net 5
l l l l l l
Ethernet LAN
ATM Switch ATM Switch ATM Switch ATM Switch
ATM Network
Transport Layer
l Transfers data end-to-end from process in a
machine to process in another machine
l Reliable stream transfer or quick-and-simple single-
block transfer
l Port numbers enable multiplexing l Message segmentation and reassembly l Connection setup, maintenance, and release
Transport Layer Network Layer Transport Layer Network Layer Network Layer Network Layer Communication Network
Application & Upper Layers
l Application Layer: Provides
services that are frequently required by applications: DNS, web acess, file transfer, email…
l Presentation Layer: machine-
independent representation of data…
l Session Layer: dialog
management, recovery from errors, …
Application Layer Presentation Layer Session Layer Transport Layer
Application
Application Layer Transport Layer
Application
Incorporated into Application Layer
Headers & Trailers
l Each protocol uses a header that carries addresses,
sequence numbers, flag bits, length indicators, etc…
l CRC check bits may be appended for error detection
Application Layer Transport Layer Network Layer Data Link Layer Physical Layer Application Layer Transport Layer Network Layer Data Link Layer Physical Layer
Application Application APP DATA AH APP DATA TH AH APP DATA NH TH AH APP DATA DH NH TH AH APP DATA CRC bits
Chapter 2 Applications and Layered Architectures
TCP/IP Architecture How the Layers Work Together
Why Internetworking?
l To build a network of networks or internet
l operating over multiple, coexisting, different network
technologies
l providing ubiquitous connectivity through IP packet transfer l achieving huge economies of scale
G G G G G G
H
Net 5 Net 5
H
Net 5 Net 2
H
Net 5 Net 3
H
Net 5 Net 1 Net 5 Net 4
Why Internetworking?
l To provide universal communication services
l independent of underlying network technologies l providing common interface to user applications
G G G G G G H
Net 5 Net 5
H
Net 5 Net 2
H
Net 5 Net 3
H
Net 5 Net 1 Net 5 Net 4
Reliable Stream Service User Datagram Service
Why Internetworking?
l To provide distributed applications
l Any application designed to operate based on
Internet communication services immediately
- perates across the entire Internet
l Rapid deployment of new applications l Email, WWW, Peer-to-peer
l Applications independent of network
technology
l New networks can be introduced below l Old network technologies can be retired
Internet Protocol Approach
l IP packets transfer information across Internet
Host A IP → router→ router…→ router→ Host B IP
l IP layer in each router determines next hop (router) l Network interfaces transfer IP packets across networks Router
Internet Layer Network Interface
Transport Layer Internet Layer Network Interface
Transport Layer Internet Layer Network Interface
Host A
Host B Net 5 Net 1 Net 5 Net 2 Net 5 Net 3
Router
Internet Layer Network Interface
Router
Internet Layer Network Interface
Net 5 Net 4
TCP/IP Protocol Suite
(ICMP, ARP) Diverse network technologies Reliable stream service User datagram service Distributed applications
HTTP SMTP RTP TCP UDP IP Network interface 1 Network interface 3 Network interface 2 DNS
Best-effort connectionless packet transfer
Internet Names & Addresses
Internet Names
l
Each host a a unique name
l Independent of physical
location
l Facilitate memorization by
humans
l Domain Name l Organization under single
administrative unit
l
Host Name
l Name given to host
computer
l
User Name
l Name assigned to user
leongarcia@comm.utoronto.ca
Internet Addresses
l
Each host has globally unique logical 32 bit IP address
l
Separate address for each physical connection to a network
l
Routing decision is done based
- n destination IP address
l
IP address has two parts:
l
netid and hostid
l
netid unique
l
netid facilitates routing
l
Dotted Decimal Notation: int1.int2.int3.int4 (intj = jth octet) 128.100.10.13 DNS resolves IP name to IP address
Physical Addresses
l LANs (and other networks) assign physical
addresses to the physical attachment to the network
l The network uses its own address to transfer
packets or frames to the appropriate destination
l IP address needs to be resolved to physical address
at each IP network interface
l Example: Ethernet uses 48-bit addresses
l Each Ethernet network interface card (NIC) has globally
unique Medium Access Control (MAC) or physical address
l First 24 bits identify NIC manufacturer; second 24 bits are
serial number
l 00:90:27:96:68:07 12 hex numbers
Intel
Example internet
(1,1) s (1,2) w (2,1) (1,3) r (2,2)
PPP Netid=2 Ethernet (netid=1)
PC Server Router Workstation
netid hostid Physical address server 1 1 s workstation 1 2 w router 1 3 r router 2 1
- PC
2 2
- *PPP does not use addresses
Encapsulation
l Ethernet header contains: l source and destination physical addresses l network protocol type (e.g. IP)
IP header
IP Payload
Ethernet header
FCS
IP header
IP Payload
IP packet from workstation to server
1.
IP packet has (1,2) IP address for source and (1,1) IP address for destination
2.
IP table at workstation indicates (1,1) connected to same network, so IP packet is encapsulated in Ethernet frame with addresses w and s
3.
Ethernet frame is broadcast by workstation NIC and captured by server NIC
4.
NIC examines protocol type field and then delivers packet to its IP layer
(1,1) s (1,2)
w
(2,1) (1,3) r (2,2) PPP Ethernet PC Server Router Workstation
(1,2), (1,1) w, s
IP packet from server to PC
(1,1) s (1,2)
w
(2,1) (1,3) r (2,2) PC Server Router Workstation
1.
IP packet has (1,1) and (2,2) as IP source and destination addresses
2.
IP table at server indicates packet should be sent to router, so IP packet is encapsulated in Ethernet frame with addresses s and r
3.
Ethernet frame is broadcast by server NIC and captured by router NIC
4.
NIC examines protocol type field and then delivers packet to its IP layer
5.
IP layer examines IP packet destination address and determines IP packet should be routed to (2,2)
6.
Routers table indicates (2,2) is directly connected via PPP link
7.
IP packet is encapsulated in PPP frame and delivered to PC
8.
PPP at PC examines protocol type field and delivers packet to PC IP layer
(1,1), (2,2) s, r (1,1), (2,2)
How the layers work together
Network interface
IP TCP
HTTP
Network interface
IP
Network interface
IP TCP HTTP Ethernet PPP Router (1,1) s (2,1) (1,3) r (2,2) PPP Ethernet (a) (b) Server PC PC Server Router TCP uses node-to-node Unreliable packet transfer of IP Server IP address & PC IP address
Internet
HTTP uses process-to-process Reliable byte stream transfer of TCP connection: Server socket: (IP Address, 80) PC socket (IP Address, Eph. #)
Encapsulation
TCP Header contains source & destination port numbers IP Header contains source and destination IP addresses; transport protocol type Ethernet Header contains source & destination MAC addresses; network protocol type
HTTP Request
TCP header
HTTP Request
IP header TCP header
HTTP Request
Ethernet header IP header TCP header
HTTP Request
FCS
l User clicks on http://www.nytimes.com/ l Ethereal network analyzer captures all frames
- bserved by its Ethernet NIC
l Sequence of frames and contents of frame can be
examined in detail down to individual bytes
How the layers work together: Network Analyzer Example
Internet
Ethereal windows
Top Pane shows frame/packet sequence Middle Pane shows encapsulation for a given frame Bottom Pane shows hex & text
Top pane: frame sequence
DNS Query
TCP Connection Setup HTTP Request & Response
Middle pane: Encapsulation
Ethernet Frame Ethernet Destination and Source Addresses Protocol Type
Middle pane: Encapsulation
IP Packet IP Source and Destination Addresses Protocol Type
And a lot of
- ther stuff!
Middle pane: Encapsulation
TCP Segment Source and Destination Port Numbers HTTP Request GET
Summary
l Encapsulation is key to layering l IP provides for transfer of packets across
diverse networks
l TCP and UDP provide universal
communications services across the Internet
l Distributed applications that use TCP and
UDP can operate over the entire Internet
l Internet names, IP addresses, port numbers,
sockets, connections, physical addresses
Chapter 2 Applications and Layered Architectures
Application Layer Protocols HTTP RTP & SIP
HTTP Protocol
l HTTP servers use well-known port 80 l Client request / Server reply l Stateless: server does not keep any
information about client
l HTTP 1.0 new TCP connection per
request/reply (non-persistent)
l HTTP 1.1 persistent operation is default
HTTP Message Formats
l HTTP messages written in ASCII text l Request Message Format
l Request Line (Each line ends with carriage return)
l Method URL HTTP-Version \r\n l Method specifies action to apply to object l URL specifies object
l Header Lines (Ea. line ends with carriage return)
l Attribute Name: Attribute Value l E.g. type of client, content, identity of requester, … l Last header line has extra carriage return)
l Entity Body (Content)
l Additional information to server
HTTP Request Methods
Request method Meaning GET Retrieve information (object) identified by the URL. HEAD Retrieve meta-information about the object, but do not transfer the object; Can be used to find out if a document has changed. POST Send information to a URL (using the entity body) and retrieve result; used when a user fills out a form in a browser. PUT Store information in location named by URL DELETE Remove object identified by URL TRACE Trace HTTP forwarding through proxies, tunnels, etc. OPTIONS Used to determine the capabilities of the server, or characteristics of a named resource.
Universal Resource Locator
l Absolute URL
l scheme://hostname[:port]/path l http://www.nytimes.com/
l Relative URL
l /path l /
HTTP Request Message
HTTP Response Message
l Response Message Format
l Status Line
l HTTP-Version Status-Code Message l Status Code: 3-digit code indicating result l E.g. HTTP/1.0 200 OK
l Headers Section
l Information about object transferred to client l E.g. server type, content length, content type, …
l Content
l Object (document)
HTTP Response Message
Cookies and Web Sessions
l Cookies are data exchanged by clients & servers as
header lines
l Since HTTP stateless, cookies can provide context
for HTTP interaction
l Set cookie header line in reply message from server
+ unique ID number for client
l If client accepts cookie, cookie added to clients
cookie file (must include expiration date)
l Henceforth client requests include ID l Server site can track client interactions, store these
in a separate database, and access database to prepare appropriate responses
Cookie Header Line; ID is 24 hexadecimal numeral
Voice Over IP
Digitization Timing Recovery RTP over UDP
Digitization of Analog Signal
l Sample analog signal in time and amplitude l Find closest binary representation
D/2 3D/2 5D/2 7D/2
- D/2
- 3D/2
- 5D/2
- 7D/2
Original signal Sample value Approximation
Rs = Bit rate = # bits/sample x # samples/second = n bits/sample 2 W samples/sec
3 bits / sample
Example: Voice & Audio
Telephone voice
l Ws = 4 kHz → 8000
samples/sec
l 8 bits/sample l Rs=8 x 8000 = 64 kbps l Cellular phones use
more powerful compression algorithms: 8-12 kbps CD Audio
l Ws = 22 kHertz → 44000
samples/sec
l 16 bits/sample l Rs=16 x 44000= 704 kbps
per audio channel
l MP3 uses more powerful
compression algorithms: 50 kbps per audio channel
Network
Synchronous source sends periodic information blocks Network output not periodic
Timing Recovery for Synchronous Services
l
Voice, audio, or video generate a synchronous information stream
l
Information carried by equally-spaced fixed-length packets
l
Packet switching introduces random delays
l
Timing recovery is needed to re-establish the synchronous nature of the stream
Introduce Playout Buffer
Playout Buffer
Packet Arrivals Packet Playout
- Delay first packet by maximum network delay
- All other packets arrive with less delay
- Playout packet uniformly thereafter
Packet Arrivals Packet Playout Tmax
Sequence numbers help order packets
Send times Playout times Arrival times
Tplayout time Time
Receiver too slow; buffer fills and
- verflows
Tplayout time Time
Receiver too fast buffer starvation Many late packets
Tplayout time Time
Receiver speed just right
Playout clock must be synchronized to transmitter clock
Recovered clock t4 t3 t2 t1 Timestamps Add Smoothing filter Adjust frequency Counter +
- Buffer for information blocks
Error signal
Playout command
Clock Recovery
l
Counter attempts to replicate transmitter clock
l
Frequency of counter is adjusted according to arriving timestamps
l
Jitter introduced by network causes fluctuations in buffer & in local clock
Timestamps inserted in packet payloads indicate when info was produced
Real-Time Protocol
l RTP designed to support real-time applications
such as voice, audio, video
l RTP provides means to carry:
l Type of information source l Sequence numbers l Timestamps
l Timing recovery done by higher layer protocol
l MPEG for video, MP3 for audio
l RTP runs over UDP
Time Stamp CSRC Identifier V P X CC M Payload Type Sequence Number SSRC Identifier
0 8 16 31
RTP Packet Format
l Payload Type: e.g. PCM, MPEG2, … l Sequence Number: detect packet loss l Timestamp: sampling instant of first byte l Synchronization Source: ID for synch source l CSRC List: contributing sources to payload
RTP Packet
RTP Control Protocol (RTCP)
l RTP companion protocol l Monitors quality of service at receivers l Conveys monitored info to senders l Canonical Name CNAME for each participant l RTCP Packets
l Sender Report Packet l Receiver Report Packet l Source Description (SDES) l BYE: end of participation by sender l APP: application specific functions
Session Initiation Protocol
l Session: association involving exchange of
data between Internet end systems
l Internet telephone call; multimedia
videoconference; instant messaging; event notification
l Session Initiation Protocol
l Setting up, maintaining, terminating session l People & media devices l Multicast or mesh of unicast connections l Support for user mobility l Over UDP or TCP
(1)
INVITE sip: tom@startup.com c= IN IPv4 192.168.12.5 m=audio 35092 RTP/AVP 0 INVITE sip: tom@192.168.15.17 c= IN IPv4 192.168.12.5 m=audio 35092 RTP/AVP 0
(2) (3)
(4) (5) ringing (6)
SIP/2.0 200 OK SIP/2.0 200 OK
(7)
ACK
(8)
Media flow
(9)
proxy registrar
Chapter 2 Applications and Layered Architectures
Sockets
Socket API
l API (Application Programming Interface)
l Provides a standard set of functions that can be
called by applications
l Berkeley UNIX Sockets API
l Abstraction for applications to send & receive data l Applications create sockets that plug into network l Applications write/read to/from sockets l Implemented in the kernel l Facilitates development of network applications l Hides details of underlying protocols & mechanisms
l Also in Windows, Linux, and other OSs
Communications through Socket Interface
Client Server
descriptor port number descriptor port number
- Application references a
socket through a descriptor
- Socket bound to a port number
Application 1 Socket Socket interface User Kernel Application 2 User Kernel Underlying communication protocols Underlying communication protocols Communications network Socket Socket interface
Stream mode of service
Connection-oriented
l First, setup connection
between two peer application processes
l Then, reliable bidirectional
in-sequence transfer of byte stream (boundaries not preserved in transfer)
l Multiple write/read between
peer processes
l Finally, connection release l Uses TCP l Connectionless l Immediate transfer of one
block of information (boundaries preserved)
l No setup overhead & delay l Destination address with
each block
l Send/receive to/from
multiple peer processes
l Best-effort service only
l
Possible out-of-order
l
Possible loss
l Uses UDP
Client & Server Differences
l Server
l Specifies well-known port # when creating socket l May have multiple IP addresses (net interfaces) l Waits passively for client requests
l Client
l Assigned ephemeral port # l Initiates communications with server l Needs to know servers IP address & port #
l DNS for URL & server well-known port #
l Server learns clients address & port #
Socket Calls for Connection- Oriented Mode
socket() socket() bind() read() close() Data Data
Server Client
listen() accept() Blocks write() connect() Connect negotiation write() read()
Server does Passive Open
l
socket creates socket to listen for connection requests
l
Server specifies type: TCP (stream)
l
socket call returns: non-negative integer descriptor;
- r -1 if unsuccessful
close()
Socket Calls for Connection- Oriented Mode
socket() socket() bind() read() close() Data Data
Server Client
listen() accept() Blocks write() connect() Connect negotiation write() read()
Server does Passive Open
l
bind assigns local address & port # to socket with specified descriptor
l
Can wildcard IP address for multiple net interfaces
l
bind call returns: 0 (success); or -1 (failure)
l
Failure if port # already in use or if reuse option not set
close()
Socket Calls for Connection- Oriented Mode
socket() socket() bind() read() close() Data Data
Server Client
listen() accept() Blocks write() connect() Connect negotiation write() read()
Server does Passive Open
l
listen indicates to TCP readiness to receive connection requests for socket with given descriptor
l
Parameter specifies max number of requests that may be queued while waiting for server to accept them
l
listen call returns: 0 (success); or -1 (failure)
close()
Socket Calls for Connection- Oriented Mode
socket() socket() bind() read() close() Data Data
Server Client
listen() accept() Blocks write() connect() Connect negotiation write() read()
Server does Passive Open
l
Server calls accept to accept incoming requests
l
accept blocks if queue is empty
close()
Socket Calls for Connection- Oriented Mode
socket() socket() bind() read() close() Data Data
Server Client
listen() accept() Blocks write() connect() Connect negotiation write() read() close()
Client does Active Open
l
socket creates socket to connect to server
l
Client specifies type: TCP (stream)
l
socket call returns: non-negative integer descriptor;
- r -1 if unsuccessful
Socket Calls for Connection- Oriented Mode
socket() socket() bind() read() close() Data Data
Server Client
listen() accept() Blocks write() connect() Connect negotiation write() read() close()
Client does Active Open
l
connect establishes a connection on the local socket with the specified descriptor to the specified remote address and port #
l
connect returns 0 if successful; -1 if unsuccessful
Note: connect initiates TCP three-way handshake
Socket Calls for Connection- Oriented Mode
socket() socket() bind() read() close() Data Data
Server Client
listen() accept() Blocks write() connect() Connect negotiation write() read()
l
accept wakes with incoming connection request
l
accept fills client address & port # into address structure
l
accept call returns: descriptor of new connection socket (success); or -1 (failure)
l
Client & server use new socket for data transfer
l
Original socket continues to listen for new requests
close()
Socket Calls for Connection- Oriented Mode
socket() socket() bind() read() close() Data Data
Server Client
listen() accept() Blocks write() connect() Connect negotiation write() read()
Data Transfer
l
Client or server call write to transmit data into a connected socket
l
write specifies: socket descriptor; pointer to a buffer; amount of data; flags to control transmission behavior
l
write call returns: # bytes transferred (success); or -1 (failure); blocks until all data transferred
close()
Socket Calls for Connection- Oriented Mode
socket() socket() bind() read() close() Data Data
Server Client
listen() accept() Blocks write() connect() Connect negotiation write() read()
Data Transfer
l
Client or server call read to receive data from a connected socket
l
read specifies: socket descriptor; pointer to a buffer; amount of data
l
read call returns: # bytes read (success); or -1 (failure); blocks if no data arrives
close()
Note: write and read can be called multiple times to transfer byte streams in both directions
Socket Calls for Connection- Oriented Mode
socket() socket() bind() read() close() Data Data
Server Client
listen() accept() Blocks write() connect() Connect negotiation write() read()
Connection Termination
l
Client or server call close when socket is no longer needed
l
close specifies the socket descriptor
l
close call returns: 0 (success); or -1 (failure)
Note: close initiates TCP graceful close sequence
close()
socket()
Socket Calls for Connection-Less Mode
sendto() socket() recvfrom() Data
Server Client
bind() Blocks until server receives data from client recvfrom() close() close() Data sendto()
Server started
l
socket creates socket of type UDP (datagram)
l
socket call returns: descriptor; or -1 if unsuccessful
l
bind assigns local address & port # to socket with specified descriptor; Can wildcard IP address
socket()
Socket Calls for Connection-Less Mode
sendto() socket() recvfrom() Data
Server Client
bind() Blocks until server receives data from client recvfrom() close() close() Data sendto()
l
recvfrom copies bytes received in specified socket into a specified location
l
recvfrom blocks until data arrives
sendto() socket()
Socket Calls for Connection-Less Mode
sendto() socket() recvfrom() Data
Server Client
bind() Blocks until server receives data from client recvfrom() close() close() Data
Client started
l
socket creates socket of type UDP (datagram)
l
socket call returns: descriptor; or -1 if unsuccessful
sendto() socket()
Socket Calls for Connection-Less Mode
sendto() socket() recvfrom() Data
Server Client
bind() Blocks until server receives data from client recvfrom() close() close() Data
Client started
l
sendto transfer bytes in buffer to specified socket
l
sendto specifies: socket descriptor; pointer to a buffer; amount of data; flags to control transmission behavior; destination address & port #; length of destination address structure
l
sendto returns: # bytes sent; or -1 if unsuccessful
socket()
Socket Calls for Connection-Less Mode
sendto() socket() recvfrom() Data
Server Client
bind() Blocks until server receives data from client recvfrom() close() close() Data sendto()
l
recvfrom wakes when data arrives
l
recvfrom specifies: socket descriptor; pointer to a buffer to put data; max # bytes to put in buffer; control flags; copies: sender address & port #; length of sender address structure
l
recvfrom returns # bytes received or -1 (failure) Note: receivefrom returns data from at most one send, i.e. from one datagram
socket()
Socket Calls for Connection-Less Mode
sendto() socket() recvfrom() Data
Server Client
bind() Blocks until server receives data from client recvfrom() close() close() Data sendto()
Socket Close
l
Client or server call close when socket is no longer needed
l
close specifies the socket descriptor
l
close call returns: 0 (success); or -1 (failure)