27
18-1 Last time Fast retransmit 3 duplicate ACKs Flow control Receiver windows Connection management SYN/SYNACK/ACK, FIN/ACK, TCP states Congestion control General concepts TCP congestion control AIMD, slow start, congestion avoidance

18-1 Last time □ Fast retransmit ♦ 3 duplicate ACKs □ Flow control ♦ Receiver windows □ Connection management ♦ SYN/SYNACK/ACK, FIN/ACK, TCP states □ Congestion

Embed Size (px)

Citation preview

Page 1: 18-1 Last time □ Fast retransmit ♦ 3 duplicate ACKs □ Flow control ♦ Receiver windows □ Connection management ♦ SYN/SYNACK/ACK, FIN/ACK, TCP states □ Congestion

18-1

Last time

Fast retransmitdiams 3 duplicate ACKs

Flow controldiams Receiver windows

Connection managementdiams SYNSYNACKACK FINACK TCP states

Congestion controldiams General concepts

TCP congestion controldiams AIMD slow start congestion avoidance

18-2

This time

TCP

diams Throughput

diams Fairness

diams Delay modeling

TCP socket programming

18-3

TCP sender congestion control

SS or CA

SS or CA

SS or CA

CongestionAvoidance (CA)

Slow Start (SS)

State

CongWin and Threshold not changed

Increment duplicate ACK count for segment being acked

Duplicate ACK

Enter slow startThreshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo

Timeout

Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS

Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo

Loss event detected by triple duplicate ACK

Additive increase resulting in increase of CongWin by 1 MSS every RTT

CongWin = CongWin+MSS (MSSCongWin)

ACK receipt for previously unacked data

Resulting in a doubling of CongWin every RTT

CongWin = CongWin + MSS If (CongWin gt Threshold) set state to ldquoCongestion Avoidancerdquo

ACK receipt for previously unacked data

CommentaryTCP Sender Action Event

18-4

TCP Throughput

Whatrsquos the average throughout of TCP as a function of window size and RTTdiams Ignore slow start

Let W be the window size when loss occurs When window is W throughput is WRTT Just after loss window drops to W2

throughput to W2RTT Average throughout 75 WRTT

18-5

TCP Futures TCP over ldquolong fat pipesrdquo

Example 1500 byte segments 100ms RTT want 10 Gbps throughput

Requires window size W = 83333 in-flight segments Throughput in terms of loss rate

L = 210-10 Wow New versions of TCP for high-speed needed

1 22sdotMSSRTT L

18-6

Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK

TCP connection 1

bottleneckrouter

capacity R

TCP connection 2

TCP Fairness

18-7

Why is TCP fair

Two competing sessions Additive increase gives slope of 1 as throughout increases multiplicative decrease decreases throughput proportionally

R

R

equal bandwidth share

Connection 1 throughput

Con

nect

ion

2 th

roug

hput

congestion avoidance additive increaseloss decrease window by factor of 2

congestion avoidance additive increaseloss decrease window by factor of 2

18-8

Fairness (more)

Fairness and UDP Multimedia apps often

do not use TCPdiams do not want rate throttled

by congestion control Instead use UDP

diams pump audiovideo at constant rate tolerate packet loss

Research area TCP friendly

Fairness and parallel TCP connections

Nothing prevents app from opening parallel connections between 2 hosts

Web browsers do this Example link of rate R

supporting 9 connections diams new app asks for 1 TCP gets

rate R10diams new app asks for 11 TCPs

gets R2

18-9

Delay modeling

Q How long does it take to receive an object from a Web server after sending a request

Ignoring congestion delay is influenced by

TCP connection establishment data transmission delay slow start

Notation assumptions Assume one link between

client and server of rate R S MSS (bits) O object size (bits) no retransmissions (no loss

no corruption)

Window size First assume fixed

congestion window W segments

Then dynamic window modeling slow start

18-10

Fixed congestion window (1)

First caseWSR gt RTT + SR ACK for

first segment in window returns before windowrsquos worth of data sent

delay = 2RTT + OR

18-11

Fixed congestion window (2)

Second case WSR lt RTT + SR wait

for ACK after sending windowrsquos worth of data sent

delay = 2RTT + OR+ (K-1)[SR + RTT - WSR]

18-12

TCP Delay Modeling Slow Start (1)

Now suppose window grows according to slow start

Will show that the delay for one object is

Latency=2 RTT OR

P [RTT SR ]minus2Pminus1 S

R

where P is the number of times TCP idles at server

P = m in Q K minus 1

- where Q is the number of times the server idles if the object were of infinite size

- and K is the number of windows that cover the object

18-13

TCP Delay Modeling Slow Start (2)

RTT

initia te TCPconnection

requestobject

first w indow= S R

second w indow= 2S R

third w indow= 4S R

fourth w indow= 8S R

com pletetransm issionobject

delivered

tim e atc lient

tim e atserver

Examplebull OS = 15 segmentsbull K = 4 windowsbull Q = 2bull P = minK-1Q = 2

Server idles P=2 times

Delay componentsbull 2 RTT for connection estab and requestbull OR to transmit objectbull time server idles due to slow start

Server idles P = minK-1Q times

18-14

TCP Delay Modeling (3)

delay=OR

2 RTT sump=1

P

idleTime p

iquestOR

2 RTTsumk=1

P

[ SR

RTTminus2kminus1 SR

]

iquestOR

2 RTTP [RTT SR

]minus 2Pminus1 SR

[ SRRTT minus2kminus1 SR ]

= idle time after the k th window

SR

RTT= time from when server starts to send segment

until server receives acknowledgement

2kminus1 SR

=time to transmit the kth window

RTT

initia te TCPconnection

requestobject

first w indow= S R

second w indow= 2S R

third w indow= 4S R

fourth w indow= 8S R

com pletetransm issionobject

delivered

tim e atc lient

tim e atserver

18-15

TCP Delay Modeling (4)

Calculation of Q number of idles for infinite-size objectis similar (see text)

Recall K = number of windows that cover object

How do we calculate K

K=min k 20S21 S⋯2kminus1SgeO iquest min k 2021⋯2kminus1geO S

iquest min k 2kminus1geOS

iquest min k kgelog2OS

1

iquest lceil log2OS

1rceil

18-16

Chapter 2 Application layer

21 Principles of network applications

22 Web and HTTP 23 FTP 24 Electronic Mail

diams SMTP POP3 IMAP

25 DNS

26 P2P file sharing 27 Socket programming

with TCP 28 Socket programming

with UDP 29 Building a Web server

18-17

Socket-programming using TCP

Socket a door between application process and end-end-transport protocol (UCP or TCP)

TCP service reliable transfer of bytes from one process to another

process

TCP withbuffers

variables

socket

controlled byapplicationdeveloper

controlled byoperating

system

host orserver

process

TCP withbuffers

variables

socket

controlled byapplicationdeveloper

controlled byoperatingsystem

host orserver

internet

18-18

Socket programming with TCP

Client must contact server server process must first be

running server must have created

socket that welcomes clientrsquos contact

Client contacts server by creating client-local TCP

socket specifying IP address port

number of server process When client creates socket

client TCP establishes connection to server TCP

When contacted by client server TCP creates new socket for server process to communicate with clientdiams allows server to talk with

multiple clientsdiams source port numbers used

to distinguish clients

TCP provides reliable in-order transfer of bytes (ldquopiperdquo) between client and server

application viewpoint

18-19

Clientserver socket interaction TCP

wait for incomingconnection requestconnectionSocket =welcomeSocketaccept()

create socketport=x forincoming requestwelcomeSocket =

ServerSocket(x)

create socketconnect to hostid port=xclientSocket = Socket(hostid x)

closeconnectionSocket

read reply fromclientSocket

closeclientSocket

Server (running on hostid) Client

send request usingclientSocketread request from

connectionSocket

write reply toconnectionSocket

TCP connection setup

18-20ou

tToS

erve

r

to network from network

inFr

omS

erve

r

inFr

omU

ser

keyboard monitor

Process

clientSocket

inputstream

inputstream

outputstream

TCPsocket

Clientprocess

client TCP socket

Stream jargon

A stream is a sequence of characters that flow into or out of a process

An input stream is attached to some input source for the process eg keyboard or socket

An output stream is attached to an output source eg monitor or socket

18-21

Socket programming with TCP

Example client-server app1) client reads line from standard

input (inFromUser stream) sends to server via socket (outToServer stream)

2) server reads line from socket3) server converts line to

uppercase sends back to client4) client reads prints modified line

from socket (inFromServer stream)

18-22

Example Java client (TCP)

import javaio import javanet class TCPClient

public static void main(String argv[]) throws Exception String sentence String modifiedSentence

BufferedReader inFromUser = new BufferedReader(new InputStreamReader(Systemin))

Socket clientSocket = new Socket(hostname 6789)

DataOutputStream outToServer = new DataOutputStream(clientSocketgetOutputStream())

Createinput stream

Create client socket

connect to server

Createoutput stream

attached to socket

18-23

Example Java client (TCP) cont

BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocketgetInputStream()))

sentence = inFromUserreadLine()

outToServerwriteBytes(sentence + n)

modifiedSentence = inFromServerreadLine()

Systemoutprintln(FROM SERVER + modifiedSentence)

clientSocketclose()

Createinput stream

attached to socket

Send lineto server

Read linefrom server

18-24

Example Java server (TCP)

import javaio import javanet

class TCPServer

public static void main(String argv[]) throws Exception String clientSentence String capitalizedSentence

ServerSocket welcomeSocket = new ServerSocket(6789) while(true) Socket connectionSocket = welcomeSocketaccept()

BufferedReader inFromClient = new BufferedReader(new InputStreamReader(connectionSocketgetInputStream()))

Createwelcoming socket

at port 6789

Wait on welcomingsocket for contact

by client

Create inputstream attached

to socket

18-25

Example Java server (TCP) cont

DataOutputStream outToClient = new DataOutputStream(connectionSocketgetOutputStream())

clientSentence = inFromClientreadLine()

capitalizedSentence = clientSentencetoUpperCase() + n

outToClientwriteBytes(capitalizedSentence)

connectionSocketclose()

Read in linefrom socket

Create outputstream attached

to socket

Write out lineto socket

End of while looploop back and wait foranother client connection

18-26

Recap

TCP

diams Throughput

diams Fairness

diams Delay modeling

TCP socket programming

18-27

Next time

NAT

Application layer

diams Intro

diams Web HTTP

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
Page 2: 18-1 Last time □ Fast retransmit ♦ 3 duplicate ACKs □ Flow control ♦ Receiver windows □ Connection management ♦ SYN/SYNACK/ACK, FIN/ACK, TCP states □ Congestion

18-2

This time

TCP

diams Throughput

diams Fairness

diams Delay modeling

TCP socket programming

18-3

TCP sender congestion control

SS or CA

SS or CA

SS or CA

CongestionAvoidance (CA)

Slow Start (SS)

State

CongWin and Threshold not changed

Increment duplicate ACK count for segment being acked

Duplicate ACK

Enter slow startThreshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo

Timeout

Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS

Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo

Loss event detected by triple duplicate ACK

Additive increase resulting in increase of CongWin by 1 MSS every RTT

CongWin = CongWin+MSS (MSSCongWin)

ACK receipt for previously unacked data

Resulting in a doubling of CongWin every RTT

CongWin = CongWin + MSS If (CongWin gt Threshold) set state to ldquoCongestion Avoidancerdquo

ACK receipt for previously unacked data

CommentaryTCP Sender Action Event

18-4

TCP Throughput

Whatrsquos the average throughout of TCP as a function of window size and RTTdiams Ignore slow start

Let W be the window size when loss occurs When window is W throughput is WRTT Just after loss window drops to W2

throughput to W2RTT Average throughout 75 WRTT

18-5

TCP Futures TCP over ldquolong fat pipesrdquo

Example 1500 byte segments 100ms RTT want 10 Gbps throughput

Requires window size W = 83333 in-flight segments Throughput in terms of loss rate

L = 210-10 Wow New versions of TCP for high-speed needed

1 22sdotMSSRTT L

18-6

Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK

TCP connection 1

bottleneckrouter

capacity R

TCP connection 2

TCP Fairness

18-7

Why is TCP fair

Two competing sessions Additive increase gives slope of 1 as throughout increases multiplicative decrease decreases throughput proportionally

R

R

equal bandwidth share

Connection 1 throughput

Con

nect

ion

2 th

roug

hput

congestion avoidance additive increaseloss decrease window by factor of 2

congestion avoidance additive increaseloss decrease window by factor of 2

18-8

Fairness (more)

Fairness and UDP Multimedia apps often

do not use TCPdiams do not want rate throttled

by congestion control Instead use UDP

diams pump audiovideo at constant rate tolerate packet loss

Research area TCP friendly

Fairness and parallel TCP connections

Nothing prevents app from opening parallel connections between 2 hosts

Web browsers do this Example link of rate R

supporting 9 connections diams new app asks for 1 TCP gets

rate R10diams new app asks for 11 TCPs

gets R2

18-9

Delay modeling

Q How long does it take to receive an object from a Web server after sending a request

Ignoring congestion delay is influenced by

TCP connection establishment data transmission delay slow start

Notation assumptions Assume one link between

client and server of rate R S MSS (bits) O object size (bits) no retransmissions (no loss

no corruption)

Window size First assume fixed

congestion window W segments

Then dynamic window modeling slow start

18-10

Fixed congestion window (1)

First caseWSR gt RTT + SR ACK for

first segment in window returns before windowrsquos worth of data sent

delay = 2RTT + OR

18-11

Fixed congestion window (2)

Second case WSR lt RTT + SR wait

for ACK after sending windowrsquos worth of data sent

delay = 2RTT + OR+ (K-1)[SR + RTT - WSR]

18-12

TCP Delay Modeling Slow Start (1)

Now suppose window grows according to slow start

Will show that the delay for one object is

Latency=2 RTT OR

P [RTT SR ]minus2Pminus1 S

R

where P is the number of times TCP idles at server

P = m in Q K minus 1

- where Q is the number of times the server idles if the object were of infinite size

- and K is the number of windows that cover the object

18-13

TCP Delay Modeling Slow Start (2)

RTT

initia te TCPconnection

requestobject

first w indow= S R

second w indow= 2S R

third w indow= 4S R

fourth w indow= 8S R

com pletetransm issionobject

delivered

tim e atc lient

tim e atserver

Examplebull OS = 15 segmentsbull K = 4 windowsbull Q = 2bull P = minK-1Q = 2

Server idles P=2 times

Delay componentsbull 2 RTT for connection estab and requestbull OR to transmit objectbull time server idles due to slow start

Server idles P = minK-1Q times

18-14

TCP Delay Modeling (3)

delay=OR

2 RTT sump=1

P

idleTime p

iquestOR

2 RTTsumk=1

P

[ SR

RTTminus2kminus1 SR

]

iquestOR

2 RTTP [RTT SR

]minus 2Pminus1 SR

[ SRRTT minus2kminus1 SR ]

= idle time after the k th window

SR

RTT= time from when server starts to send segment

until server receives acknowledgement

2kminus1 SR

=time to transmit the kth window

RTT

initia te TCPconnection

requestobject

first w indow= S R

second w indow= 2S R

third w indow= 4S R

fourth w indow= 8S R

com pletetransm issionobject

delivered

tim e atc lient

tim e atserver

18-15

TCP Delay Modeling (4)

Calculation of Q number of idles for infinite-size objectis similar (see text)

Recall K = number of windows that cover object

How do we calculate K

K=min k 20S21 S⋯2kminus1SgeO iquest min k 2021⋯2kminus1geO S

iquest min k 2kminus1geOS

iquest min k kgelog2OS

1

iquest lceil log2OS

1rceil

18-16

Chapter 2 Application layer

21 Principles of network applications

22 Web and HTTP 23 FTP 24 Electronic Mail

diams SMTP POP3 IMAP

25 DNS

26 P2P file sharing 27 Socket programming

with TCP 28 Socket programming

with UDP 29 Building a Web server

18-17

Socket-programming using TCP

Socket a door between application process and end-end-transport protocol (UCP or TCP)

TCP service reliable transfer of bytes from one process to another

process

TCP withbuffers

variables

socket

controlled byapplicationdeveloper

controlled byoperating

system

host orserver

process

TCP withbuffers

variables

socket

controlled byapplicationdeveloper

controlled byoperatingsystem

host orserver

internet

18-18

Socket programming with TCP

Client must contact server server process must first be

running server must have created

socket that welcomes clientrsquos contact

Client contacts server by creating client-local TCP

socket specifying IP address port

number of server process When client creates socket

client TCP establishes connection to server TCP

When contacted by client server TCP creates new socket for server process to communicate with clientdiams allows server to talk with

multiple clientsdiams source port numbers used

to distinguish clients

TCP provides reliable in-order transfer of bytes (ldquopiperdquo) between client and server

application viewpoint

18-19

Clientserver socket interaction TCP

wait for incomingconnection requestconnectionSocket =welcomeSocketaccept()

create socketport=x forincoming requestwelcomeSocket =

ServerSocket(x)

create socketconnect to hostid port=xclientSocket = Socket(hostid x)

closeconnectionSocket

read reply fromclientSocket

closeclientSocket

Server (running on hostid) Client

send request usingclientSocketread request from

connectionSocket

write reply toconnectionSocket

TCP connection setup

18-20ou

tToS

erve

r

to network from network

inFr

omS

erve

r

inFr

omU

ser

keyboard monitor

Process

clientSocket

inputstream

inputstream

outputstream

TCPsocket

Clientprocess

client TCP socket

Stream jargon

A stream is a sequence of characters that flow into or out of a process

An input stream is attached to some input source for the process eg keyboard or socket

An output stream is attached to an output source eg monitor or socket

18-21

Socket programming with TCP

Example client-server app1) client reads line from standard

input (inFromUser stream) sends to server via socket (outToServer stream)

2) server reads line from socket3) server converts line to

uppercase sends back to client4) client reads prints modified line

from socket (inFromServer stream)

18-22

Example Java client (TCP)

import javaio import javanet class TCPClient

public static void main(String argv[]) throws Exception String sentence String modifiedSentence

BufferedReader inFromUser = new BufferedReader(new InputStreamReader(Systemin))

Socket clientSocket = new Socket(hostname 6789)

DataOutputStream outToServer = new DataOutputStream(clientSocketgetOutputStream())

Createinput stream

Create client socket

connect to server

Createoutput stream

attached to socket

18-23

Example Java client (TCP) cont

BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocketgetInputStream()))

sentence = inFromUserreadLine()

outToServerwriteBytes(sentence + n)

modifiedSentence = inFromServerreadLine()

Systemoutprintln(FROM SERVER + modifiedSentence)

clientSocketclose()

Createinput stream

attached to socket

Send lineto server

Read linefrom server

18-24

Example Java server (TCP)

import javaio import javanet

class TCPServer

public static void main(String argv[]) throws Exception String clientSentence String capitalizedSentence

ServerSocket welcomeSocket = new ServerSocket(6789) while(true) Socket connectionSocket = welcomeSocketaccept()

BufferedReader inFromClient = new BufferedReader(new InputStreamReader(connectionSocketgetInputStream()))

Createwelcoming socket

at port 6789

Wait on welcomingsocket for contact

by client

Create inputstream attached

to socket

18-25

Example Java server (TCP) cont

DataOutputStream outToClient = new DataOutputStream(connectionSocketgetOutputStream())

clientSentence = inFromClientreadLine()

capitalizedSentence = clientSentencetoUpperCase() + n

outToClientwriteBytes(capitalizedSentence)

connectionSocketclose()

Read in linefrom socket

Create outputstream attached

to socket

Write out lineto socket

End of while looploop back and wait foranother client connection

18-26

Recap

TCP

diams Throughput

diams Fairness

diams Delay modeling

TCP socket programming

18-27

Next time

NAT

Application layer

diams Intro

diams Web HTTP

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
Page 3: 18-1 Last time □ Fast retransmit ♦ 3 duplicate ACKs □ Flow control ♦ Receiver windows □ Connection management ♦ SYN/SYNACK/ACK, FIN/ACK, TCP states □ Congestion

18-3

TCP sender congestion control

SS or CA

SS or CA

SS or CA

CongestionAvoidance (CA)

Slow Start (SS)

State

CongWin and Threshold not changed

Increment duplicate ACK count for segment being acked

Duplicate ACK

Enter slow startThreshold = CongWin2 CongWin = 1 MSSSet state to ldquoSlow Startrdquo

Timeout

Fast recovery implementing multiplicative decrease CongWin will not drop below 1 MSS

Threshold = CongWin2 CongWin = ThresholdSet state to ldquoCongestion Avoidancerdquo

Loss event detected by triple duplicate ACK

Additive increase resulting in increase of CongWin by 1 MSS every RTT

CongWin = CongWin+MSS (MSSCongWin)

ACK receipt for previously unacked data

Resulting in a doubling of CongWin every RTT

CongWin = CongWin + MSS If (CongWin gt Threshold) set state to ldquoCongestion Avoidancerdquo

ACK receipt for previously unacked data

CommentaryTCP Sender Action Event

18-4

TCP Throughput

Whatrsquos the average throughout of TCP as a function of window size and RTTdiams Ignore slow start

Let W be the window size when loss occurs When window is W throughput is WRTT Just after loss window drops to W2

throughput to W2RTT Average throughout 75 WRTT

18-5

TCP Futures TCP over ldquolong fat pipesrdquo

Example 1500 byte segments 100ms RTT want 10 Gbps throughput

Requires window size W = 83333 in-flight segments Throughput in terms of loss rate

L = 210-10 Wow New versions of TCP for high-speed needed

1 22sdotMSSRTT L

18-6

Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK

TCP connection 1

bottleneckrouter

capacity R

TCP connection 2

TCP Fairness

18-7

Why is TCP fair

Two competing sessions Additive increase gives slope of 1 as throughout increases multiplicative decrease decreases throughput proportionally

R

R

equal bandwidth share

Connection 1 throughput

Con

nect

ion

2 th

roug

hput

congestion avoidance additive increaseloss decrease window by factor of 2

congestion avoidance additive increaseloss decrease window by factor of 2

18-8

Fairness (more)

Fairness and UDP Multimedia apps often

do not use TCPdiams do not want rate throttled

by congestion control Instead use UDP

diams pump audiovideo at constant rate tolerate packet loss

Research area TCP friendly

Fairness and parallel TCP connections

Nothing prevents app from opening parallel connections between 2 hosts

Web browsers do this Example link of rate R

supporting 9 connections diams new app asks for 1 TCP gets

rate R10diams new app asks for 11 TCPs

gets R2

18-9

Delay modeling

Q How long does it take to receive an object from a Web server after sending a request

Ignoring congestion delay is influenced by

TCP connection establishment data transmission delay slow start

Notation assumptions Assume one link between

client and server of rate R S MSS (bits) O object size (bits) no retransmissions (no loss

no corruption)

Window size First assume fixed

congestion window W segments

Then dynamic window modeling slow start

18-10

Fixed congestion window (1)

First caseWSR gt RTT + SR ACK for

first segment in window returns before windowrsquos worth of data sent

delay = 2RTT + OR

18-11

Fixed congestion window (2)

Second case WSR lt RTT + SR wait

for ACK after sending windowrsquos worth of data sent

delay = 2RTT + OR+ (K-1)[SR + RTT - WSR]

18-12

TCP Delay Modeling Slow Start (1)

Now suppose window grows according to slow start

Will show that the delay for one object is

Latency=2 RTT OR

P [RTT SR ]minus2Pminus1 S

R

where P is the number of times TCP idles at server

P = m in Q K minus 1

- where Q is the number of times the server idles if the object were of infinite size

- and K is the number of windows that cover the object

18-13

TCP Delay Modeling Slow Start (2)

RTT

initia te TCPconnection

requestobject

first w indow= S R

second w indow= 2S R

third w indow= 4S R

fourth w indow= 8S R

com pletetransm issionobject

delivered

tim e atc lient

tim e atserver

Examplebull OS = 15 segmentsbull K = 4 windowsbull Q = 2bull P = minK-1Q = 2

Server idles P=2 times

Delay componentsbull 2 RTT for connection estab and requestbull OR to transmit objectbull time server idles due to slow start

Server idles P = minK-1Q times

18-14

TCP Delay Modeling (3)

delay=OR

2 RTT sump=1

P

idleTime p

iquestOR

2 RTTsumk=1

P

[ SR

RTTminus2kminus1 SR

]

iquestOR

2 RTTP [RTT SR

]minus 2Pminus1 SR

[ SRRTT minus2kminus1 SR ]

= idle time after the k th window

SR

RTT= time from when server starts to send segment

until server receives acknowledgement

2kminus1 SR

=time to transmit the kth window

RTT

initia te TCPconnection

requestobject

first w indow= S R

second w indow= 2S R

third w indow= 4S R

fourth w indow= 8S R

com pletetransm issionobject

delivered

tim e atc lient

tim e atserver

18-15

TCP Delay Modeling (4)

Calculation of Q number of idles for infinite-size objectis similar (see text)

Recall K = number of windows that cover object

How do we calculate K

K=min k 20S21 S⋯2kminus1SgeO iquest min k 2021⋯2kminus1geO S

iquest min k 2kminus1geOS

iquest min k kgelog2OS

1

iquest lceil log2OS

1rceil

18-16

Chapter 2 Application layer

21 Principles of network applications

22 Web and HTTP 23 FTP 24 Electronic Mail

diams SMTP POP3 IMAP

25 DNS

26 P2P file sharing 27 Socket programming

with TCP 28 Socket programming

with UDP 29 Building a Web server

18-17

Socket-programming using TCP

Socket a door between application process and end-end-transport protocol (UCP or TCP)

TCP service reliable transfer of bytes from one process to another

process

TCP withbuffers

variables

socket

controlled byapplicationdeveloper

controlled byoperating

system

host orserver

process

TCP withbuffers

variables

socket

controlled byapplicationdeveloper

controlled byoperatingsystem

host orserver

internet

18-18

Socket programming with TCP

Client must contact server server process must first be

running server must have created

socket that welcomes clientrsquos contact

Client contacts server by creating client-local TCP

socket specifying IP address port

number of server process When client creates socket

client TCP establishes connection to server TCP

When contacted by client server TCP creates new socket for server process to communicate with clientdiams allows server to talk with

multiple clientsdiams source port numbers used

to distinguish clients

TCP provides reliable in-order transfer of bytes (ldquopiperdquo) between client and server

application viewpoint

18-19

Clientserver socket interaction TCP

wait for incomingconnection requestconnectionSocket =welcomeSocketaccept()

create socketport=x forincoming requestwelcomeSocket =

ServerSocket(x)

create socketconnect to hostid port=xclientSocket = Socket(hostid x)

closeconnectionSocket

read reply fromclientSocket

closeclientSocket

Server (running on hostid) Client

send request usingclientSocketread request from

connectionSocket

write reply toconnectionSocket

TCP connection setup

18-20ou

tToS

erve

r

to network from network

inFr

omS

erve

r

inFr

omU

ser

keyboard monitor

Process

clientSocket

inputstream

inputstream

outputstream

TCPsocket

Clientprocess

client TCP socket

Stream jargon

A stream is a sequence of characters that flow into or out of a process

An input stream is attached to some input source for the process eg keyboard or socket

An output stream is attached to an output source eg monitor or socket

18-21

Socket programming with TCP

Example client-server app1) client reads line from standard

input (inFromUser stream) sends to server via socket (outToServer stream)

2) server reads line from socket3) server converts line to

uppercase sends back to client4) client reads prints modified line

from socket (inFromServer stream)

18-22

Example Java client (TCP)

import javaio import javanet class TCPClient

public static void main(String argv[]) throws Exception String sentence String modifiedSentence

BufferedReader inFromUser = new BufferedReader(new InputStreamReader(Systemin))

Socket clientSocket = new Socket(hostname 6789)

DataOutputStream outToServer = new DataOutputStream(clientSocketgetOutputStream())

Createinput stream

Create client socket

connect to server

Createoutput stream

attached to socket

18-23

Example Java client (TCP) cont

BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocketgetInputStream()))

sentence = inFromUserreadLine()

outToServerwriteBytes(sentence + n)

modifiedSentence = inFromServerreadLine()

Systemoutprintln(FROM SERVER + modifiedSentence)

clientSocketclose()

Createinput stream

attached to socket

Send lineto server

Read linefrom server

18-24

Example Java server (TCP)

import javaio import javanet

class TCPServer

public static void main(String argv[]) throws Exception String clientSentence String capitalizedSentence

ServerSocket welcomeSocket = new ServerSocket(6789) while(true) Socket connectionSocket = welcomeSocketaccept()

BufferedReader inFromClient = new BufferedReader(new InputStreamReader(connectionSocketgetInputStream()))

Createwelcoming socket

at port 6789

Wait on welcomingsocket for contact

by client

Create inputstream attached

to socket

18-25

Example Java server (TCP) cont

DataOutputStream outToClient = new DataOutputStream(connectionSocketgetOutputStream())

clientSentence = inFromClientreadLine()

capitalizedSentence = clientSentencetoUpperCase() + n

outToClientwriteBytes(capitalizedSentence)

connectionSocketclose()

Read in linefrom socket

Create outputstream attached

to socket

Write out lineto socket

End of while looploop back and wait foranother client connection

18-26

Recap

TCP

diams Throughput

diams Fairness

diams Delay modeling

TCP socket programming

18-27

Next time

NAT

Application layer

diams Intro

diams Web HTTP

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
Page 4: 18-1 Last time □ Fast retransmit ♦ 3 duplicate ACKs □ Flow control ♦ Receiver windows □ Connection management ♦ SYN/SYNACK/ACK, FIN/ACK, TCP states □ Congestion

18-4

TCP Throughput

Whatrsquos the average throughout of TCP as a function of window size and RTTdiams Ignore slow start

Let W be the window size when loss occurs When window is W throughput is WRTT Just after loss window drops to W2

throughput to W2RTT Average throughout 75 WRTT

18-5

TCP Futures TCP over ldquolong fat pipesrdquo

Example 1500 byte segments 100ms RTT want 10 Gbps throughput

Requires window size W = 83333 in-flight segments Throughput in terms of loss rate

L = 210-10 Wow New versions of TCP for high-speed needed

1 22sdotMSSRTT L

18-6

Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK

TCP connection 1

bottleneckrouter

capacity R

TCP connection 2

TCP Fairness

18-7

Why is TCP fair

Two competing sessions Additive increase gives slope of 1 as throughout increases multiplicative decrease decreases throughput proportionally

R

R

equal bandwidth share

Connection 1 throughput

Con

nect

ion

2 th

roug

hput

congestion avoidance additive increaseloss decrease window by factor of 2

congestion avoidance additive increaseloss decrease window by factor of 2

18-8

Fairness (more)

Fairness and UDP Multimedia apps often

do not use TCPdiams do not want rate throttled

by congestion control Instead use UDP

diams pump audiovideo at constant rate tolerate packet loss

Research area TCP friendly

Fairness and parallel TCP connections

Nothing prevents app from opening parallel connections between 2 hosts

Web browsers do this Example link of rate R

supporting 9 connections diams new app asks for 1 TCP gets

rate R10diams new app asks for 11 TCPs

gets R2

18-9

Delay modeling

Q How long does it take to receive an object from a Web server after sending a request

Ignoring congestion delay is influenced by

TCP connection establishment data transmission delay slow start

Notation assumptions Assume one link between

client and server of rate R S MSS (bits) O object size (bits) no retransmissions (no loss

no corruption)

Window size First assume fixed

congestion window W segments

Then dynamic window modeling slow start

18-10

Fixed congestion window (1)

First caseWSR gt RTT + SR ACK for

first segment in window returns before windowrsquos worth of data sent

delay = 2RTT + OR

18-11

Fixed congestion window (2)

Second case WSR lt RTT + SR wait

for ACK after sending windowrsquos worth of data sent

delay = 2RTT + OR+ (K-1)[SR + RTT - WSR]

18-12

TCP Delay Modeling Slow Start (1)

Now suppose window grows according to slow start

Will show that the delay for one object is

Latency=2 RTT OR

P [RTT SR ]minus2Pminus1 S

R

where P is the number of times TCP idles at server

P = m in Q K minus 1

- where Q is the number of times the server idles if the object were of infinite size

- and K is the number of windows that cover the object

18-13

TCP Delay Modeling Slow Start (2)

RTT

initia te TCPconnection

requestobject

first w indow= S R

second w indow= 2S R

third w indow= 4S R

fourth w indow= 8S R

com pletetransm issionobject

delivered

tim e atc lient

tim e atserver

Examplebull OS = 15 segmentsbull K = 4 windowsbull Q = 2bull P = minK-1Q = 2

Server idles P=2 times

Delay componentsbull 2 RTT for connection estab and requestbull OR to transmit objectbull time server idles due to slow start

Server idles P = minK-1Q times

18-14

TCP Delay Modeling (3)

delay=OR

2 RTT sump=1

P

idleTime p

iquestOR

2 RTTsumk=1

P

[ SR

RTTminus2kminus1 SR

]

iquestOR

2 RTTP [RTT SR

]minus 2Pminus1 SR

[ SRRTT minus2kminus1 SR ]

= idle time after the k th window

SR

RTT= time from when server starts to send segment

until server receives acknowledgement

2kminus1 SR

=time to transmit the kth window

RTT

initia te TCPconnection

requestobject

first w indow= S R

second w indow= 2S R

third w indow= 4S R

fourth w indow= 8S R

com pletetransm issionobject

delivered

tim e atc lient

tim e atserver

18-15

TCP Delay Modeling (4)

Calculation of Q number of idles for infinite-size objectis similar (see text)

Recall K = number of windows that cover object

How do we calculate K

K=min k 20S21 S⋯2kminus1SgeO iquest min k 2021⋯2kminus1geO S

iquest min k 2kminus1geOS

iquest min k kgelog2OS

1

iquest lceil log2OS

1rceil

18-16

Chapter 2 Application layer

21 Principles of network applications

22 Web and HTTP 23 FTP 24 Electronic Mail

diams SMTP POP3 IMAP

25 DNS

26 P2P file sharing 27 Socket programming

with TCP 28 Socket programming

with UDP 29 Building a Web server

18-17

Socket-programming using TCP

Socket a door between application process and end-end-transport protocol (UCP or TCP)

TCP service reliable transfer of bytes from one process to another

process

TCP withbuffers

variables

socket

controlled byapplicationdeveloper

controlled byoperating

system

host orserver

process

TCP withbuffers

variables

socket

controlled byapplicationdeveloper

controlled byoperatingsystem

host orserver

internet

18-18

Socket programming with TCP

Client must contact server server process must first be

running server must have created

socket that welcomes clientrsquos contact

Client contacts server by creating client-local TCP

socket specifying IP address port

number of server process When client creates socket

client TCP establishes connection to server TCP

When contacted by client server TCP creates new socket for server process to communicate with clientdiams allows server to talk with

multiple clientsdiams source port numbers used

to distinguish clients

TCP provides reliable in-order transfer of bytes (ldquopiperdquo) between client and server

application viewpoint

18-19

Clientserver socket interaction TCP

wait for incomingconnection requestconnectionSocket =welcomeSocketaccept()

create socketport=x forincoming requestwelcomeSocket =

ServerSocket(x)

create socketconnect to hostid port=xclientSocket = Socket(hostid x)

closeconnectionSocket

read reply fromclientSocket

closeclientSocket

Server (running on hostid) Client

send request usingclientSocketread request from

connectionSocket

write reply toconnectionSocket

TCP connection setup

18-20ou

tToS

erve

r

to network from network

inFr

omS

erve

r

inFr

omU

ser

keyboard monitor

Process

clientSocket

inputstream

inputstream

outputstream

TCPsocket

Clientprocess

client TCP socket

Stream jargon

A stream is a sequence of characters that flow into or out of a process

An input stream is attached to some input source for the process eg keyboard or socket

An output stream is attached to an output source eg monitor or socket

18-21

Socket programming with TCP

Example client-server app1) client reads line from standard

input (inFromUser stream) sends to server via socket (outToServer stream)

2) server reads line from socket3) server converts line to

uppercase sends back to client4) client reads prints modified line

from socket (inFromServer stream)

18-22

Example Java client (TCP)

import javaio import javanet class TCPClient

public static void main(String argv[]) throws Exception String sentence String modifiedSentence

BufferedReader inFromUser = new BufferedReader(new InputStreamReader(Systemin))

Socket clientSocket = new Socket(hostname 6789)

DataOutputStream outToServer = new DataOutputStream(clientSocketgetOutputStream())

Createinput stream

Create client socket

connect to server

Createoutput stream

attached to socket

18-23

Example Java client (TCP) cont

BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocketgetInputStream()))

sentence = inFromUserreadLine()

outToServerwriteBytes(sentence + n)

modifiedSentence = inFromServerreadLine()

Systemoutprintln(FROM SERVER + modifiedSentence)

clientSocketclose()

Createinput stream

attached to socket

Send lineto server

Read linefrom server

18-24

Example Java server (TCP)

import javaio import javanet

class TCPServer

public static void main(String argv[]) throws Exception String clientSentence String capitalizedSentence

ServerSocket welcomeSocket = new ServerSocket(6789) while(true) Socket connectionSocket = welcomeSocketaccept()

BufferedReader inFromClient = new BufferedReader(new InputStreamReader(connectionSocketgetInputStream()))

Createwelcoming socket

at port 6789

Wait on welcomingsocket for contact

by client

Create inputstream attached

to socket

18-25

Example Java server (TCP) cont

DataOutputStream outToClient = new DataOutputStream(connectionSocketgetOutputStream())

clientSentence = inFromClientreadLine()

capitalizedSentence = clientSentencetoUpperCase() + n

outToClientwriteBytes(capitalizedSentence)

connectionSocketclose()

Read in linefrom socket

Create outputstream attached

to socket

Write out lineto socket

End of while looploop back and wait foranother client connection

18-26

Recap

TCP

diams Throughput

diams Fairness

diams Delay modeling

TCP socket programming

18-27

Next time

NAT

Application layer

diams Intro

diams Web HTTP

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
Page 5: 18-1 Last time □ Fast retransmit ♦ 3 duplicate ACKs □ Flow control ♦ Receiver windows □ Connection management ♦ SYN/SYNACK/ACK, FIN/ACK, TCP states □ Congestion

18-5

TCP Futures TCP over ldquolong fat pipesrdquo

Example 1500 byte segments 100ms RTT want 10 Gbps throughput

Requires window size W = 83333 in-flight segments Throughput in terms of loss rate

L = 210-10 Wow New versions of TCP for high-speed needed

1 22sdotMSSRTT L

18-6

Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK

TCP connection 1

bottleneckrouter

capacity R

TCP connection 2

TCP Fairness

18-7

Why is TCP fair

Two competing sessions Additive increase gives slope of 1 as throughout increases multiplicative decrease decreases throughput proportionally

R

R

equal bandwidth share

Connection 1 throughput

Con

nect

ion

2 th

roug

hput

congestion avoidance additive increaseloss decrease window by factor of 2

congestion avoidance additive increaseloss decrease window by factor of 2

18-8

Fairness (more)

Fairness and UDP Multimedia apps often

do not use TCPdiams do not want rate throttled

by congestion control Instead use UDP

diams pump audiovideo at constant rate tolerate packet loss

Research area TCP friendly

Fairness and parallel TCP connections

Nothing prevents app from opening parallel connections between 2 hosts

Web browsers do this Example link of rate R

supporting 9 connections diams new app asks for 1 TCP gets

rate R10diams new app asks for 11 TCPs

gets R2

18-9

Delay modeling

Q How long does it take to receive an object from a Web server after sending a request

Ignoring congestion delay is influenced by

TCP connection establishment data transmission delay slow start

Notation assumptions Assume one link between

client and server of rate R S MSS (bits) O object size (bits) no retransmissions (no loss

no corruption)

Window size First assume fixed

congestion window W segments

Then dynamic window modeling slow start

18-10

Fixed congestion window (1)

First caseWSR gt RTT + SR ACK for

first segment in window returns before windowrsquos worth of data sent

delay = 2RTT + OR

18-11

Fixed congestion window (2)

Second case WSR lt RTT + SR wait

for ACK after sending windowrsquos worth of data sent

delay = 2RTT + OR+ (K-1)[SR + RTT - WSR]

18-12

TCP Delay Modeling Slow Start (1)

Now suppose window grows according to slow start

Will show that the delay for one object is

Latency=2 RTT OR

P [RTT SR ]minus2Pminus1 S

R

where P is the number of times TCP idles at server

P = m in Q K minus 1

- where Q is the number of times the server idles if the object were of infinite size

- and K is the number of windows that cover the object

18-13

TCP Delay Modeling Slow Start (2)

RTT

initia te TCPconnection

requestobject

first w indow= S R

second w indow= 2S R

third w indow= 4S R

fourth w indow= 8S R

com pletetransm issionobject

delivered

tim e atc lient

tim e atserver

Examplebull OS = 15 segmentsbull K = 4 windowsbull Q = 2bull P = minK-1Q = 2

Server idles P=2 times

Delay componentsbull 2 RTT for connection estab and requestbull OR to transmit objectbull time server idles due to slow start

Server idles P = minK-1Q times

18-14

TCP Delay Modeling (3)

delay=OR

2 RTT sump=1

P

idleTime p

iquestOR

2 RTTsumk=1

P

[ SR

RTTminus2kminus1 SR

]

iquestOR

2 RTTP [RTT SR

]minus 2Pminus1 SR

[ SRRTT minus2kminus1 SR ]

= idle time after the k th window

SR

RTT= time from when server starts to send segment

until server receives acknowledgement

2kminus1 SR

=time to transmit the kth window

RTT

initia te TCPconnection

requestobject

first w indow= S R

second w indow= 2S R

third w indow= 4S R

fourth w indow= 8S R

com pletetransm issionobject

delivered

tim e atc lient

tim e atserver

18-15

TCP Delay Modeling (4)

Calculation of Q number of idles for infinite-size objectis similar (see text)

Recall K = number of windows that cover object

How do we calculate K

K=min k 20S21 S⋯2kminus1SgeO iquest min k 2021⋯2kminus1geO S

iquest min k 2kminus1geOS

iquest min k kgelog2OS

1

iquest lceil log2OS

1rceil

18-16

Chapter 2 Application layer

21 Principles of network applications

22 Web and HTTP 23 FTP 24 Electronic Mail

diams SMTP POP3 IMAP

25 DNS

26 P2P file sharing 27 Socket programming

with TCP 28 Socket programming

with UDP 29 Building a Web server

18-17

Socket-programming using TCP

Socket a door between application process and end-end-transport protocol (UCP or TCP)

TCP service reliable transfer of bytes from one process to another

process

TCP withbuffers

variables

socket

controlled byapplicationdeveloper

controlled byoperating

system

host orserver

process

TCP withbuffers

variables

socket

controlled byapplicationdeveloper

controlled byoperatingsystem

host orserver

internet

18-18

Socket programming with TCP

Client must contact server server process must first be

running server must have created

socket that welcomes clientrsquos contact

Client contacts server by creating client-local TCP

socket specifying IP address port

number of server process When client creates socket

client TCP establishes connection to server TCP

When contacted by client server TCP creates new socket for server process to communicate with clientdiams allows server to talk with

multiple clientsdiams source port numbers used

to distinguish clients

TCP provides reliable in-order transfer of bytes (ldquopiperdquo) between client and server

application viewpoint

18-19

Clientserver socket interaction TCP

wait for incomingconnection requestconnectionSocket =welcomeSocketaccept()

create socketport=x forincoming requestwelcomeSocket =

ServerSocket(x)

create socketconnect to hostid port=xclientSocket = Socket(hostid x)

closeconnectionSocket

read reply fromclientSocket

closeclientSocket

Server (running on hostid) Client

send request usingclientSocketread request from

connectionSocket

write reply toconnectionSocket

TCP connection setup

18-20ou

tToS

erve

r

to network from network

inFr

omS

erve

r

inFr

omU

ser

keyboard monitor

Process

clientSocket

inputstream

inputstream

outputstream

TCPsocket

Clientprocess

client TCP socket

Stream jargon

A stream is a sequence of characters that flow into or out of a process

An input stream is attached to some input source for the process eg keyboard or socket

An output stream is attached to an output source eg monitor or socket

18-21

Socket programming with TCP

Example client-server app1) client reads line from standard

input (inFromUser stream) sends to server via socket (outToServer stream)

2) server reads line from socket3) server converts line to

uppercase sends back to client4) client reads prints modified line

from socket (inFromServer stream)

18-22

Example Java client (TCP)

import javaio import javanet class TCPClient

public static void main(String argv[]) throws Exception String sentence String modifiedSentence

BufferedReader inFromUser = new BufferedReader(new InputStreamReader(Systemin))

Socket clientSocket = new Socket(hostname 6789)

DataOutputStream outToServer = new DataOutputStream(clientSocketgetOutputStream())

Createinput stream

Create client socket

connect to server

Createoutput stream

attached to socket

18-23

Example Java client (TCP) cont

BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocketgetInputStream()))

sentence = inFromUserreadLine()

outToServerwriteBytes(sentence + n)

modifiedSentence = inFromServerreadLine()

Systemoutprintln(FROM SERVER + modifiedSentence)

clientSocketclose()

Createinput stream

attached to socket

Send lineto server

Read linefrom server

18-24

Example Java server (TCP)

import javaio import javanet

class TCPServer

public static void main(String argv[]) throws Exception String clientSentence String capitalizedSentence

ServerSocket welcomeSocket = new ServerSocket(6789) while(true) Socket connectionSocket = welcomeSocketaccept()

BufferedReader inFromClient = new BufferedReader(new InputStreamReader(connectionSocketgetInputStream()))

Createwelcoming socket

at port 6789

Wait on welcomingsocket for contact

by client

Create inputstream attached

to socket

18-25

Example Java server (TCP) cont

DataOutputStream outToClient = new DataOutputStream(connectionSocketgetOutputStream())

clientSentence = inFromClientreadLine()

capitalizedSentence = clientSentencetoUpperCase() + n

outToClientwriteBytes(capitalizedSentence)

connectionSocketclose()

Read in linefrom socket

Create outputstream attached

to socket

Write out lineto socket

End of while looploop back and wait foranother client connection

18-26

Recap

TCP

diams Throughput

diams Fairness

diams Delay modeling

TCP socket programming

18-27

Next time

NAT

Application layer

diams Intro

diams Web HTTP

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
Page 6: 18-1 Last time □ Fast retransmit ♦ 3 duplicate ACKs □ Flow control ♦ Receiver windows □ Connection management ♦ SYN/SYNACK/ACK, FIN/ACK, TCP states □ Congestion

18-6

Fairness goal if K TCP sessions share same bottleneck link of bandwidth R each should have average rate of RK

TCP connection 1

bottleneckrouter

capacity R

TCP connection 2

TCP Fairness

18-7

Why is TCP fair

Two competing sessions Additive increase gives slope of 1 as throughout increases multiplicative decrease decreases throughput proportionally

R

R

equal bandwidth share

Connection 1 throughput

Con

nect

ion

2 th

roug

hput

congestion avoidance additive increaseloss decrease window by factor of 2

congestion avoidance additive increaseloss decrease window by factor of 2

18-8

Fairness (more)

Fairness and UDP Multimedia apps often

do not use TCPdiams do not want rate throttled

by congestion control Instead use UDP

diams pump audiovideo at constant rate tolerate packet loss

Research area TCP friendly

Fairness and parallel TCP connections

Nothing prevents app from opening parallel connections between 2 hosts

Web browsers do this Example link of rate R

supporting 9 connections diams new app asks for 1 TCP gets

rate R10diams new app asks for 11 TCPs

gets R2

18-9

Delay modeling

Q How long does it take to receive an object from a Web server after sending a request

Ignoring congestion delay is influenced by

TCP connection establishment data transmission delay slow start

Notation assumptions Assume one link between

client and server of rate R S MSS (bits) O object size (bits) no retransmissions (no loss

no corruption)

Window size First assume fixed

congestion window W segments

Then dynamic window modeling slow start

18-10

Fixed congestion window (1)

First caseWSR gt RTT + SR ACK for

first segment in window returns before windowrsquos worth of data sent

delay = 2RTT + OR

18-11

Fixed congestion window (2)

Second case WSR lt RTT + SR wait

for ACK after sending windowrsquos worth of data sent

delay = 2RTT + OR+ (K-1)[SR + RTT - WSR]

18-12

TCP Delay Modeling Slow Start (1)

Now suppose window grows according to slow start

Will show that the delay for one object is

Latency=2 RTT OR

P [RTT SR ]minus2Pminus1 S

R

where P is the number of times TCP idles at server

P = m in Q K minus 1

- where Q is the number of times the server idles if the object were of infinite size

- and K is the number of windows that cover the object

18-13

TCP Delay Modeling Slow Start (2)

RTT

initia te TCPconnection

requestobject

first w indow= S R

second w indow= 2S R

third w indow= 4S R

fourth w indow= 8S R

com pletetransm issionobject

delivered

tim e atc lient

tim e atserver

Examplebull OS = 15 segmentsbull K = 4 windowsbull Q = 2bull P = minK-1Q = 2

Server idles P=2 times

Delay componentsbull 2 RTT for connection estab and requestbull OR to transmit objectbull time server idles due to slow start

Server idles P = minK-1Q times

18-14

TCP Delay Modeling (3)

delay=OR

2 RTT sump=1

P

idleTime p

iquestOR

2 RTTsumk=1

P

[ SR

RTTminus2kminus1 SR

]

iquestOR

2 RTTP [RTT SR

]minus 2Pminus1 SR

[ SRRTT minus2kminus1 SR ]

= idle time after the k th window

SR

RTT= time from when server starts to send segment

until server receives acknowledgement

2kminus1 SR

=time to transmit the kth window

RTT

initia te TCPconnection

requestobject

first w indow= S R

second w indow= 2S R

third w indow= 4S R

fourth w indow= 8S R

com pletetransm issionobject

delivered

tim e atc lient

tim e atserver

18-15

TCP Delay Modeling (4)

Calculation of Q number of idles for infinite-size objectis similar (see text)

Recall K = number of windows that cover object

How do we calculate K

K=min k 20S21 S⋯2kminus1SgeO iquest min k 2021⋯2kminus1geO S

iquest min k 2kminus1geOS

iquest min k kgelog2OS

1

iquest lceil log2OS

1rceil

18-16

Chapter 2 Application layer

21 Principles of network applications

22 Web and HTTP 23 FTP 24 Electronic Mail

diams SMTP POP3 IMAP

25 DNS

26 P2P file sharing 27 Socket programming

with TCP 28 Socket programming

with UDP 29 Building a Web server

18-17

Socket-programming using TCP

Socket a door between application process and end-end-transport protocol (UCP or TCP)

TCP service reliable transfer of bytes from one process to another

process

TCP withbuffers

variables

socket

controlled byapplicationdeveloper

controlled byoperating

system

host orserver

process

TCP withbuffers

variables

socket

controlled byapplicationdeveloper

controlled byoperatingsystem

host orserver

internet

18-18

Socket programming with TCP

Client must contact server server process must first be

running server must have created

socket that welcomes clientrsquos contact

Client contacts server by creating client-local TCP

socket specifying IP address port

number of server process When client creates socket

client TCP establishes connection to server TCP

When contacted by client server TCP creates new socket for server process to communicate with clientdiams allows server to talk with

multiple clientsdiams source port numbers used

to distinguish clients

TCP provides reliable in-order transfer of bytes (ldquopiperdquo) between client and server

application viewpoint

18-19

Clientserver socket interaction TCP

wait for incomingconnection requestconnectionSocket =welcomeSocketaccept()

create socketport=x forincoming requestwelcomeSocket =

ServerSocket(x)

create socketconnect to hostid port=xclientSocket = Socket(hostid x)

closeconnectionSocket

read reply fromclientSocket

closeclientSocket

Server (running on hostid) Client

send request usingclientSocketread request from

connectionSocket

write reply toconnectionSocket

TCP connection setup

18-20ou

tToS

erve

r

to network from network

inFr

omS

erve

r

inFr

omU

ser

keyboard monitor

Process

clientSocket

inputstream

inputstream

outputstream

TCPsocket

Clientprocess

client TCP socket

Stream jargon

A stream is a sequence of characters that flow into or out of a process

An input stream is attached to some input source for the process eg keyboard or socket

An output stream is attached to an output source eg monitor or socket

18-21

Socket programming with TCP

Example client-server app1) client reads line from standard

input (inFromUser stream) sends to server via socket (outToServer stream)

2) server reads line from socket3) server converts line to

uppercase sends back to client4) client reads prints modified line

from socket (inFromServer stream)

18-22

Example Java client (TCP)

import javaio import javanet class TCPClient

public static void main(String argv[]) throws Exception String sentence String modifiedSentence

BufferedReader inFromUser = new BufferedReader(new InputStreamReader(Systemin))

Socket clientSocket = new Socket(hostname 6789)

DataOutputStream outToServer = new DataOutputStream(clientSocketgetOutputStream())

Createinput stream

Create client socket

connect to server

Createoutput stream

attached to socket

18-23

Example Java client (TCP) cont

BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocketgetInputStream()))

sentence = inFromUserreadLine()

outToServerwriteBytes(sentence + n)

modifiedSentence = inFromServerreadLine()

Systemoutprintln(FROM SERVER + modifiedSentence)

clientSocketclose()

Createinput stream

attached to socket

Send lineto server

Read linefrom server

18-24

Example Java server (TCP)

import javaio import javanet

class TCPServer

public static void main(String argv[]) throws Exception String clientSentence String capitalizedSentence

ServerSocket welcomeSocket = new ServerSocket(6789) while(true) Socket connectionSocket = welcomeSocketaccept()

BufferedReader inFromClient = new BufferedReader(new InputStreamReader(connectionSocketgetInputStream()))

Createwelcoming socket

at port 6789

Wait on welcomingsocket for contact

by client

Create inputstream attached

to socket

18-25

Example Java server (TCP) cont

DataOutputStream outToClient = new DataOutputStream(connectionSocketgetOutputStream())

clientSentence = inFromClientreadLine()

capitalizedSentence = clientSentencetoUpperCase() + n

outToClientwriteBytes(capitalizedSentence)

connectionSocketclose()

Read in linefrom socket

Create outputstream attached

to socket

Write out lineto socket

End of while looploop back and wait foranother client connection

18-26

Recap

TCP

diams Throughput

diams Fairness

diams Delay modeling

TCP socket programming

18-27

Next time

NAT

Application layer

diams Intro

diams Web HTTP

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
Page 7: 18-1 Last time □ Fast retransmit ♦ 3 duplicate ACKs □ Flow control ♦ Receiver windows □ Connection management ♦ SYN/SYNACK/ACK, FIN/ACK, TCP states □ Congestion

18-7

Why is TCP fair

Two competing sessions Additive increase gives slope of 1 as throughout increases multiplicative decrease decreases throughput proportionally

R

R

equal bandwidth share

Connection 1 throughput

Con

nect

ion

2 th

roug

hput

congestion avoidance additive increaseloss decrease window by factor of 2

congestion avoidance additive increaseloss decrease window by factor of 2

18-8

Fairness (more)

Fairness and UDP Multimedia apps often

do not use TCPdiams do not want rate throttled

by congestion control Instead use UDP

diams pump audiovideo at constant rate tolerate packet loss

Research area TCP friendly

Fairness and parallel TCP connections

Nothing prevents app from opening parallel connections between 2 hosts

Web browsers do this Example link of rate R

supporting 9 connections diams new app asks for 1 TCP gets

rate R10diams new app asks for 11 TCPs

gets R2

18-9

Delay modeling

Q How long does it take to receive an object from a Web server after sending a request

Ignoring congestion delay is influenced by

TCP connection establishment data transmission delay slow start

Notation assumptions Assume one link between

client and server of rate R S MSS (bits) O object size (bits) no retransmissions (no loss

no corruption)

Window size First assume fixed

congestion window W segments

Then dynamic window modeling slow start

18-10

Fixed congestion window (1)

First caseWSR gt RTT + SR ACK for

first segment in window returns before windowrsquos worth of data sent

delay = 2RTT + OR

18-11

Fixed congestion window (2)

Second case WSR lt RTT + SR wait

for ACK after sending windowrsquos worth of data sent

delay = 2RTT + OR+ (K-1)[SR + RTT - WSR]

18-12

TCP Delay Modeling Slow Start (1)

Now suppose window grows according to slow start

Will show that the delay for one object is

Latency=2 RTT OR

P [RTT SR ]minus2Pminus1 S

R

where P is the number of times TCP idles at server

P = m in Q K minus 1

- where Q is the number of times the server idles if the object were of infinite size

- and K is the number of windows that cover the object

18-13

TCP Delay Modeling Slow Start (2)

RTT

initia te TCPconnection

requestobject

first w indow= S R

second w indow= 2S R

third w indow= 4S R

fourth w indow= 8S R

com pletetransm issionobject

delivered

tim e atc lient

tim e atserver

Examplebull OS = 15 segmentsbull K = 4 windowsbull Q = 2bull P = minK-1Q = 2

Server idles P=2 times

Delay componentsbull 2 RTT for connection estab and requestbull OR to transmit objectbull time server idles due to slow start

Server idles P = minK-1Q times

18-14

TCP Delay Modeling (3)

delay=OR

2 RTT sump=1

P

idleTime p

iquestOR

2 RTTsumk=1

P

[ SR

RTTminus2kminus1 SR

]

iquestOR

2 RTTP [RTT SR

]minus 2Pminus1 SR

[ SRRTT minus2kminus1 SR ]

= idle time after the k th window

SR

RTT= time from when server starts to send segment

until server receives acknowledgement

2kminus1 SR

=time to transmit the kth window

RTT

initia te TCPconnection

requestobject

first w indow= S R

second w indow= 2S R

third w indow= 4S R

fourth w indow= 8S R

com pletetransm issionobject

delivered

tim e atc lient

tim e atserver

18-15

TCP Delay Modeling (4)

Calculation of Q number of idles for infinite-size objectis similar (see text)

Recall K = number of windows that cover object

How do we calculate K

K=min k 20S21 S⋯2kminus1SgeO iquest min k 2021⋯2kminus1geO S

iquest min k 2kminus1geOS

iquest min k kgelog2OS

1

iquest lceil log2OS

1rceil

18-16

Chapter 2 Application layer

21 Principles of network applications

22 Web and HTTP 23 FTP 24 Electronic Mail

diams SMTP POP3 IMAP

25 DNS

26 P2P file sharing 27 Socket programming

with TCP 28 Socket programming

with UDP 29 Building a Web server

18-17

Socket-programming using TCP

Socket a door between application process and end-end-transport protocol (UCP or TCP)

TCP service reliable transfer of bytes from one process to another

process

TCP withbuffers

variables

socket

controlled byapplicationdeveloper

controlled byoperating

system

host orserver

process

TCP withbuffers

variables

socket

controlled byapplicationdeveloper

controlled byoperatingsystem

host orserver

internet

18-18

Socket programming with TCP

Client must contact server server process must first be

running server must have created

socket that welcomes clientrsquos contact

Client contacts server by creating client-local TCP

socket specifying IP address port

number of server process When client creates socket

client TCP establishes connection to server TCP

When contacted by client server TCP creates new socket for server process to communicate with clientdiams allows server to talk with

multiple clientsdiams source port numbers used

to distinguish clients

TCP provides reliable in-order transfer of bytes (ldquopiperdquo) between client and server

application viewpoint

18-19

Clientserver socket interaction TCP

wait for incomingconnection requestconnectionSocket =welcomeSocketaccept()

create socketport=x forincoming requestwelcomeSocket =

ServerSocket(x)

create socketconnect to hostid port=xclientSocket = Socket(hostid x)

closeconnectionSocket

read reply fromclientSocket

closeclientSocket

Server (running on hostid) Client

send request usingclientSocketread request from

connectionSocket

write reply toconnectionSocket

TCP connection setup

18-20ou

tToS

erve

r

to network from network

inFr

omS

erve

r

inFr

omU

ser

keyboard monitor

Process

clientSocket

inputstream

inputstream

outputstream

TCPsocket

Clientprocess

client TCP socket

Stream jargon

A stream is a sequence of characters that flow into or out of a process

An input stream is attached to some input source for the process eg keyboard or socket

An output stream is attached to an output source eg monitor or socket

18-21

Socket programming with TCP

Example client-server app1) client reads line from standard

input (inFromUser stream) sends to server via socket (outToServer stream)

2) server reads line from socket3) server converts line to

uppercase sends back to client4) client reads prints modified line

from socket (inFromServer stream)

18-22

Example Java client (TCP)

import javaio import javanet class TCPClient

public static void main(String argv[]) throws Exception String sentence String modifiedSentence

BufferedReader inFromUser = new BufferedReader(new InputStreamReader(Systemin))

Socket clientSocket = new Socket(hostname 6789)

DataOutputStream outToServer = new DataOutputStream(clientSocketgetOutputStream())

Createinput stream

Create client socket

connect to server

Createoutput stream

attached to socket

18-23

Example Java client (TCP) cont

BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocketgetInputStream()))

sentence = inFromUserreadLine()

outToServerwriteBytes(sentence + n)

modifiedSentence = inFromServerreadLine()

Systemoutprintln(FROM SERVER + modifiedSentence)

clientSocketclose()

Createinput stream

attached to socket

Send lineto server

Read linefrom server

18-24

Example Java server (TCP)

import javaio import javanet

class TCPServer

public static void main(String argv[]) throws Exception String clientSentence String capitalizedSentence

ServerSocket welcomeSocket = new ServerSocket(6789) while(true) Socket connectionSocket = welcomeSocketaccept()

BufferedReader inFromClient = new BufferedReader(new InputStreamReader(connectionSocketgetInputStream()))

Createwelcoming socket

at port 6789

Wait on welcomingsocket for contact

by client

Create inputstream attached

to socket

18-25

Example Java server (TCP) cont

DataOutputStream outToClient = new DataOutputStream(connectionSocketgetOutputStream())

clientSentence = inFromClientreadLine()

capitalizedSentence = clientSentencetoUpperCase() + n

outToClientwriteBytes(capitalizedSentence)

connectionSocketclose()

Read in linefrom socket

Create outputstream attached

to socket

Write out lineto socket

End of while looploop back and wait foranother client connection

18-26

Recap

TCP

diams Throughput

diams Fairness

diams Delay modeling

TCP socket programming

18-27

Next time

NAT

Application layer

diams Intro

diams Web HTTP

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
Page 8: 18-1 Last time □ Fast retransmit ♦ 3 duplicate ACKs □ Flow control ♦ Receiver windows □ Connection management ♦ SYN/SYNACK/ACK, FIN/ACK, TCP states □ Congestion

18-8

Fairness (more)

Fairness and UDP Multimedia apps often

do not use TCPdiams do not want rate throttled

by congestion control Instead use UDP

diams pump audiovideo at constant rate tolerate packet loss

Research area TCP friendly

Fairness and parallel TCP connections

Nothing prevents app from opening parallel connections between 2 hosts

Web browsers do this Example link of rate R

supporting 9 connections diams new app asks for 1 TCP gets

rate R10diams new app asks for 11 TCPs

gets R2

18-9

Delay modeling

Q How long does it take to receive an object from a Web server after sending a request

Ignoring congestion delay is influenced by

TCP connection establishment data transmission delay slow start

Notation assumptions Assume one link between

client and server of rate R S MSS (bits) O object size (bits) no retransmissions (no loss

no corruption)

Window size First assume fixed

congestion window W segments

Then dynamic window modeling slow start

18-10

Fixed congestion window (1)

First caseWSR gt RTT + SR ACK for

first segment in window returns before windowrsquos worth of data sent

delay = 2RTT + OR

18-11

Fixed congestion window (2)

Second case WSR lt RTT + SR wait

for ACK after sending windowrsquos worth of data sent

delay = 2RTT + OR+ (K-1)[SR + RTT - WSR]

18-12

TCP Delay Modeling Slow Start (1)

Now suppose window grows according to slow start

Will show that the delay for one object is

Latency=2 RTT OR

P [RTT SR ]minus2Pminus1 S

R

where P is the number of times TCP idles at server

P = m in Q K minus 1

- where Q is the number of times the server idles if the object were of infinite size

- and K is the number of windows that cover the object

18-13

TCP Delay Modeling Slow Start (2)

RTT

initia te TCPconnection

requestobject

first w indow= S R

second w indow= 2S R

third w indow= 4S R

fourth w indow= 8S R

com pletetransm issionobject

delivered

tim e atc lient

tim e atserver

Examplebull OS = 15 segmentsbull K = 4 windowsbull Q = 2bull P = minK-1Q = 2

Server idles P=2 times

Delay componentsbull 2 RTT for connection estab and requestbull OR to transmit objectbull time server idles due to slow start

Server idles P = minK-1Q times

18-14

TCP Delay Modeling (3)

delay=OR

2 RTT sump=1

P

idleTime p

iquestOR

2 RTTsumk=1

P

[ SR

RTTminus2kminus1 SR

]

iquestOR

2 RTTP [RTT SR

]minus 2Pminus1 SR

[ SRRTT minus2kminus1 SR ]

= idle time after the k th window

SR

RTT= time from when server starts to send segment

until server receives acknowledgement

2kminus1 SR

=time to transmit the kth window

RTT

initia te TCPconnection

requestobject

first w indow= S R

second w indow= 2S R

third w indow= 4S R

fourth w indow= 8S R

com pletetransm issionobject

delivered

tim e atc lient

tim e atserver

18-15

TCP Delay Modeling (4)

Calculation of Q number of idles for infinite-size objectis similar (see text)

Recall K = number of windows that cover object

How do we calculate K

K=min k 20S21 S⋯2kminus1SgeO iquest min k 2021⋯2kminus1geO S

iquest min k 2kminus1geOS

iquest min k kgelog2OS

1

iquest lceil log2OS

1rceil

18-16

Chapter 2 Application layer

21 Principles of network applications

22 Web and HTTP 23 FTP 24 Electronic Mail

diams SMTP POP3 IMAP

25 DNS

26 P2P file sharing 27 Socket programming

with TCP 28 Socket programming

with UDP 29 Building a Web server

18-17

Socket-programming using TCP

Socket a door between application process and end-end-transport protocol (UCP or TCP)

TCP service reliable transfer of bytes from one process to another

process

TCP withbuffers

variables

socket

controlled byapplicationdeveloper

controlled byoperating

system

host orserver

process

TCP withbuffers

variables

socket

controlled byapplicationdeveloper

controlled byoperatingsystem

host orserver

internet

18-18

Socket programming with TCP

Client must contact server server process must first be

running server must have created

socket that welcomes clientrsquos contact

Client contacts server by creating client-local TCP

socket specifying IP address port

number of server process When client creates socket

client TCP establishes connection to server TCP

When contacted by client server TCP creates new socket for server process to communicate with clientdiams allows server to talk with

multiple clientsdiams source port numbers used

to distinguish clients

TCP provides reliable in-order transfer of bytes (ldquopiperdquo) between client and server

application viewpoint

18-19

Clientserver socket interaction TCP

wait for incomingconnection requestconnectionSocket =welcomeSocketaccept()

create socketport=x forincoming requestwelcomeSocket =

ServerSocket(x)

create socketconnect to hostid port=xclientSocket = Socket(hostid x)

closeconnectionSocket

read reply fromclientSocket

closeclientSocket

Server (running on hostid) Client

send request usingclientSocketread request from

connectionSocket

write reply toconnectionSocket

TCP connection setup

18-20ou

tToS

erve

r

to network from network

inFr

omS

erve

r

inFr

omU

ser

keyboard monitor

Process

clientSocket

inputstream

inputstream

outputstream

TCPsocket

Clientprocess

client TCP socket

Stream jargon

A stream is a sequence of characters that flow into or out of a process

An input stream is attached to some input source for the process eg keyboard or socket

An output stream is attached to an output source eg monitor or socket

18-21

Socket programming with TCP

Example client-server app1) client reads line from standard

input (inFromUser stream) sends to server via socket (outToServer stream)

2) server reads line from socket3) server converts line to

uppercase sends back to client4) client reads prints modified line

from socket (inFromServer stream)

18-22

Example Java client (TCP)

import javaio import javanet class TCPClient

public static void main(String argv[]) throws Exception String sentence String modifiedSentence

BufferedReader inFromUser = new BufferedReader(new InputStreamReader(Systemin))

Socket clientSocket = new Socket(hostname 6789)

DataOutputStream outToServer = new DataOutputStream(clientSocketgetOutputStream())

Createinput stream

Create client socket

connect to server

Createoutput stream

attached to socket

18-23

Example Java client (TCP) cont

BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocketgetInputStream()))

sentence = inFromUserreadLine()

outToServerwriteBytes(sentence + n)

modifiedSentence = inFromServerreadLine()

Systemoutprintln(FROM SERVER + modifiedSentence)

clientSocketclose()

Createinput stream

attached to socket

Send lineto server

Read linefrom server

18-24

Example Java server (TCP)

import javaio import javanet

class TCPServer

public static void main(String argv[]) throws Exception String clientSentence String capitalizedSentence

ServerSocket welcomeSocket = new ServerSocket(6789) while(true) Socket connectionSocket = welcomeSocketaccept()

BufferedReader inFromClient = new BufferedReader(new InputStreamReader(connectionSocketgetInputStream()))

Createwelcoming socket

at port 6789

Wait on welcomingsocket for contact

by client

Create inputstream attached

to socket

18-25

Example Java server (TCP) cont

DataOutputStream outToClient = new DataOutputStream(connectionSocketgetOutputStream())

clientSentence = inFromClientreadLine()

capitalizedSentence = clientSentencetoUpperCase() + n

outToClientwriteBytes(capitalizedSentence)

connectionSocketclose()

Read in linefrom socket

Create outputstream attached

to socket

Write out lineto socket

End of while looploop back and wait foranother client connection

18-26

Recap

TCP

diams Throughput

diams Fairness

diams Delay modeling

TCP socket programming

18-27

Next time

NAT

Application layer

diams Intro

diams Web HTTP

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
Page 9: 18-1 Last time □ Fast retransmit ♦ 3 duplicate ACKs □ Flow control ♦ Receiver windows □ Connection management ♦ SYN/SYNACK/ACK, FIN/ACK, TCP states □ Congestion

18-9

Delay modeling

Q How long does it take to receive an object from a Web server after sending a request

Ignoring congestion delay is influenced by

TCP connection establishment data transmission delay slow start

Notation assumptions Assume one link between

client and server of rate R S MSS (bits) O object size (bits) no retransmissions (no loss

no corruption)

Window size First assume fixed

congestion window W segments

Then dynamic window modeling slow start

18-10

Fixed congestion window (1)

First caseWSR gt RTT + SR ACK for

first segment in window returns before windowrsquos worth of data sent

delay = 2RTT + OR

18-11

Fixed congestion window (2)

Second case WSR lt RTT + SR wait

for ACK after sending windowrsquos worth of data sent

delay = 2RTT + OR+ (K-1)[SR + RTT - WSR]

18-12

TCP Delay Modeling Slow Start (1)

Now suppose window grows according to slow start

Will show that the delay for one object is

Latency=2 RTT OR

P [RTT SR ]minus2Pminus1 S

R

where P is the number of times TCP idles at server

P = m in Q K minus 1

- where Q is the number of times the server idles if the object were of infinite size

- and K is the number of windows that cover the object

18-13

TCP Delay Modeling Slow Start (2)

RTT

initia te TCPconnection

requestobject

first w indow= S R

second w indow= 2S R

third w indow= 4S R

fourth w indow= 8S R

com pletetransm issionobject

delivered

tim e atc lient

tim e atserver

Examplebull OS = 15 segmentsbull K = 4 windowsbull Q = 2bull P = minK-1Q = 2

Server idles P=2 times

Delay componentsbull 2 RTT for connection estab and requestbull OR to transmit objectbull time server idles due to slow start

Server idles P = minK-1Q times

18-14

TCP Delay Modeling (3)

delay=OR

2 RTT sump=1

P

idleTime p

iquestOR

2 RTTsumk=1

P

[ SR

RTTminus2kminus1 SR

]

iquestOR

2 RTTP [RTT SR

]minus 2Pminus1 SR

[ SRRTT minus2kminus1 SR ]

= idle time after the k th window

SR

RTT= time from when server starts to send segment

until server receives acknowledgement

2kminus1 SR

=time to transmit the kth window

RTT

initia te TCPconnection

requestobject

first w indow= S R

second w indow= 2S R

third w indow= 4S R

fourth w indow= 8S R

com pletetransm issionobject

delivered

tim e atc lient

tim e atserver

18-15

TCP Delay Modeling (4)

Calculation of Q number of idles for infinite-size objectis similar (see text)

Recall K = number of windows that cover object

How do we calculate K

K=min k 20S21 S⋯2kminus1SgeO iquest min k 2021⋯2kminus1geO S

iquest min k 2kminus1geOS

iquest min k kgelog2OS

1

iquest lceil log2OS

1rceil

18-16

Chapter 2 Application layer

21 Principles of network applications

22 Web and HTTP 23 FTP 24 Electronic Mail

diams SMTP POP3 IMAP

25 DNS

26 P2P file sharing 27 Socket programming

with TCP 28 Socket programming

with UDP 29 Building a Web server

18-17

Socket-programming using TCP

Socket a door between application process and end-end-transport protocol (UCP or TCP)

TCP service reliable transfer of bytes from one process to another

process

TCP withbuffers

variables

socket

controlled byapplicationdeveloper

controlled byoperating

system

host orserver

process

TCP withbuffers

variables

socket

controlled byapplicationdeveloper

controlled byoperatingsystem

host orserver

internet

18-18

Socket programming with TCP

Client must contact server server process must first be

running server must have created

socket that welcomes clientrsquos contact

Client contacts server by creating client-local TCP

socket specifying IP address port

number of server process When client creates socket

client TCP establishes connection to server TCP

When contacted by client server TCP creates new socket for server process to communicate with clientdiams allows server to talk with

multiple clientsdiams source port numbers used

to distinguish clients

TCP provides reliable in-order transfer of bytes (ldquopiperdquo) between client and server

application viewpoint

18-19

Clientserver socket interaction TCP

wait for incomingconnection requestconnectionSocket =welcomeSocketaccept()

create socketport=x forincoming requestwelcomeSocket =

ServerSocket(x)

create socketconnect to hostid port=xclientSocket = Socket(hostid x)

closeconnectionSocket

read reply fromclientSocket

closeclientSocket

Server (running on hostid) Client

send request usingclientSocketread request from

connectionSocket

write reply toconnectionSocket

TCP connection setup

18-20ou

tToS

erve

r

to network from network

inFr

omS

erve

r

inFr

omU

ser

keyboard monitor

Process

clientSocket

inputstream

inputstream

outputstream

TCPsocket

Clientprocess

client TCP socket

Stream jargon

A stream is a sequence of characters that flow into or out of a process

An input stream is attached to some input source for the process eg keyboard or socket

An output stream is attached to an output source eg monitor or socket

18-21

Socket programming with TCP

Example client-server app1) client reads line from standard

input (inFromUser stream) sends to server via socket (outToServer stream)

2) server reads line from socket3) server converts line to

uppercase sends back to client4) client reads prints modified line

from socket (inFromServer stream)

18-22

Example Java client (TCP)

import javaio import javanet class TCPClient

public static void main(String argv[]) throws Exception String sentence String modifiedSentence

BufferedReader inFromUser = new BufferedReader(new InputStreamReader(Systemin))

Socket clientSocket = new Socket(hostname 6789)

DataOutputStream outToServer = new DataOutputStream(clientSocketgetOutputStream())

Createinput stream

Create client socket

connect to server

Createoutput stream

attached to socket

18-23

Example Java client (TCP) cont

BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocketgetInputStream()))

sentence = inFromUserreadLine()

outToServerwriteBytes(sentence + n)

modifiedSentence = inFromServerreadLine()

Systemoutprintln(FROM SERVER + modifiedSentence)

clientSocketclose()

Createinput stream

attached to socket

Send lineto server

Read linefrom server

18-24

Example Java server (TCP)

import javaio import javanet

class TCPServer

public static void main(String argv[]) throws Exception String clientSentence String capitalizedSentence

ServerSocket welcomeSocket = new ServerSocket(6789) while(true) Socket connectionSocket = welcomeSocketaccept()

BufferedReader inFromClient = new BufferedReader(new InputStreamReader(connectionSocketgetInputStream()))

Createwelcoming socket

at port 6789

Wait on welcomingsocket for contact

by client

Create inputstream attached

to socket

18-25

Example Java server (TCP) cont

DataOutputStream outToClient = new DataOutputStream(connectionSocketgetOutputStream())

clientSentence = inFromClientreadLine()

capitalizedSentence = clientSentencetoUpperCase() + n

outToClientwriteBytes(capitalizedSentence)

connectionSocketclose()

Read in linefrom socket

Create outputstream attached

to socket

Write out lineto socket

End of while looploop back and wait foranother client connection

18-26

Recap

TCP

diams Throughput

diams Fairness

diams Delay modeling

TCP socket programming

18-27

Next time

NAT

Application layer

diams Intro

diams Web HTTP

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
Page 10: 18-1 Last time □ Fast retransmit ♦ 3 duplicate ACKs □ Flow control ♦ Receiver windows □ Connection management ♦ SYN/SYNACK/ACK, FIN/ACK, TCP states □ Congestion

18-10

Fixed congestion window (1)

First caseWSR gt RTT + SR ACK for

first segment in window returns before windowrsquos worth of data sent

delay = 2RTT + OR

18-11

Fixed congestion window (2)

Second case WSR lt RTT + SR wait

for ACK after sending windowrsquos worth of data sent

delay = 2RTT + OR+ (K-1)[SR + RTT - WSR]

18-12

TCP Delay Modeling Slow Start (1)

Now suppose window grows according to slow start

Will show that the delay for one object is

Latency=2 RTT OR

P [RTT SR ]minus2Pminus1 S

R

where P is the number of times TCP idles at server

P = m in Q K minus 1

- where Q is the number of times the server idles if the object were of infinite size

- and K is the number of windows that cover the object

18-13

TCP Delay Modeling Slow Start (2)

RTT

initia te TCPconnection

requestobject

first w indow= S R

second w indow= 2S R

third w indow= 4S R

fourth w indow= 8S R

com pletetransm issionobject

delivered

tim e atc lient

tim e atserver

Examplebull OS = 15 segmentsbull K = 4 windowsbull Q = 2bull P = minK-1Q = 2

Server idles P=2 times

Delay componentsbull 2 RTT for connection estab and requestbull OR to transmit objectbull time server idles due to slow start

Server idles P = minK-1Q times

18-14

TCP Delay Modeling (3)

delay=OR

2 RTT sump=1

P

idleTime p

iquestOR

2 RTTsumk=1

P

[ SR

RTTminus2kminus1 SR

]

iquestOR

2 RTTP [RTT SR

]minus 2Pminus1 SR

[ SRRTT minus2kminus1 SR ]

= idle time after the k th window

SR

RTT= time from when server starts to send segment

until server receives acknowledgement

2kminus1 SR

=time to transmit the kth window

RTT

initia te TCPconnection

requestobject

first w indow= S R

second w indow= 2S R

third w indow= 4S R

fourth w indow= 8S R

com pletetransm issionobject

delivered

tim e atc lient

tim e atserver

18-15

TCP Delay Modeling (4)

Calculation of Q number of idles for infinite-size objectis similar (see text)

Recall K = number of windows that cover object

How do we calculate K

K=min k 20S21 S⋯2kminus1SgeO iquest min k 2021⋯2kminus1geO S

iquest min k 2kminus1geOS

iquest min k kgelog2OS

1

iquest lceil log2OS

1rceil

18-16

Chapter 2 Application layer

21 Principles of network applications

22 Web and HTTP 23 FTP 24 Electronic Mail

diams SMTP POP3 IMAP

25 DNS

26 P2P file sharing 27 Socket programming

with TCP 28 Socket programming

with UDP 29 Building a Web server

18-17

Socket-programming using TCP

Socket a door between application process and end-end-transport protocol (UCP or TCP)

TCP service reliable transfer of bytes from one process to another

process

TCP withbuffers

variables

socket

controlled byapplicationdeveloper

controlled byoperating

system

host orserver

process

TCP withbuffers

variables

socket

controlled byapplicationdeveloper

controlled byoperatingsystem

host orserver

internet

18-18

Socket programming with TCP

Client must contact server server process must first be

running server must have created

socket that welcomes clientrsquos contact

Client contacts server by creating client-local TCP

socket specifying IP address port

number of server process When client creates socket

client TCP establishes connection to server TCP

When contacted by client server TCP creates new socket for server process to communicate with clientdiams allows server to talk with

multiple clientsdiams source port numbers used

to distinguish clients

TCP provides reliable in-order transfer of bytes (ldquopiperdquo) between client and server

application viewpoint

18-19

Clientserver socket interaction TCP

wait for incomingconnection requestconnectionSocket =welcomeSocketaccept()

create socketport=x forincoming requestwelcomeSocket =

ServerSocket(x)

create socketconnect to hostid port=xclientSocket = Socket(hostid x)

closeconnectionSocket

read reply fromclientSocket

closeclientSocket

Server (running on hostid) Client

send request usingclientSocketread request from

connectionSocket

write reply toconnectionSocket

TCP connection setup

18-20ou

tToS

erve

r

to network from network

inFr

omS

erve

r

inFr

omU

ser

keyboard monitor

Process

clientSocket

inputstream

inputstream

outputstream

TCPsocket

Clientprocess

client TCP socket

Stream jargon

A stream is a sequence of characters that flow into or out of a process

An input stream is attached to some input source for the process eg keyboard or socket

An output stream is attached to an output source eg monitor or socket

18-21

Socket programming with TCP

Example client-server app1) client reads line from standard

input (inFromUser stream) sends to server via socket (outToServer stream)

2) server reads line from socket3) server converts line to

uppercase sends back to client4) client reads prints modified line

from socket (inFromServer stream)

18-22

Example Java client (TCP)

import javaio import javanet class TCPClient

public static void main(String argv[]) throws Exception String sentence String modifiedSentence

BufferedReader inFromUser = new BufferedReader(new InputStreamReader(Systemin))

Socket clientSocket = new Socket(hostname 6789)

DataOutputStream outToServer = new DataOutputStream(clientSocketgetOutputStream())

Createinput stream

Create client socket

connect to server

Createoutput stream

attached to socket

18-23

Example Java client (TCP) cont

BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocketgetInputStream()))

sentence = inFromUserreadLine()

outToServerwriteBytes(sentence + n)

modifiedSentence = inFromServerreadLine()

Systemoutprintln(FROM SERVER + modifiedSentence)

clientSocketclose()

Createinput stream

attached to socket

Send lineto server

Read linefrom server

18-24

Example Java server (TCP)

import javaio import javanet

class TCPServer

public static void main(String argv[]) throws Exception String clientSentence String capitalizedSentence

ServerSocket welcomeSocket = new ServerSocket(6789) while(true) Socket connectionSocket = welcomeSocketaccept()

BufferedReader inFromClient = new BufferedReader(new InputStreamReader(connectionSocketgetInputStream()))

Createwelcoming socket

at port 6789

Wait on welcomingsocket for contact

by client

Create inputstream attached

to socket

18-25

Example Java server (TCP) cont

DataOutputStream outToClient = new DataOutputStream(connectionSocketgetOutputStream())

clientSentence = inFromClientreadLine()

capitalizedSentence = clientSentencetoUpperCase() + n

outToClientwriteBytes(capitalizedSentence)

connectionSocketclose()

Read in linefrom socket

Create outputstream attached

to socket

Write out lineto socket

End of while looploop back and wait foranother client connection

18-26

Recap

TCP

diams Throughput

diams Fairness

diams Delay modeling

TCP socket programming

18-27

Next time

NAT

Application layer

diams Intro

diams Web HTTP

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
Page 11: 18-1 Last time □ Fast retransmit ♦ 3 duplicate ACKs □ Flow control ♦ Receiver windows □ Connection management ♦ SYN/SYNACK/ACK, FIN/ACK, TCP states □ Congestion

18-11

Fixed congestion window (2)

Second case WSR lt RTT + SR wait

for ACK after sending windowrsquos worth of data sent

delay = 2RTT + OR+ (K-1)[SR + RTT - WSR]

18-12

TCP Delay Modeling Slow Start (1)

Now suppose window grows according to slow start

Will show that the delay for one object is

Latency=2 RTT OR

P [RTT SR ]minus2Pminus1 S

R

where P is the number of times TCP idles at server

P = m in Q K minus 1

- where Q is the number of times the server idles if the object were of infinite size

- and K is the number of windows that cover the object

18-13

TCP Delay Modeling Slow Start (2)

RTT

initia te TCPconnection

requestobject

first w indow= S R

second w indow= 2S R

third w indow= 4S R

fourth w indow= 8S R

com pletetransm issionobject

delivered

tim e atc lient

tim e atserver

Examplebull OS = 15 segmentsbull K = 4 windowsbull Q = 2bull P = minK-1Q = 2

Server idles P=2 times

Delay componentsbull 2 RTT for connection estab and requestbull OR to transmit objectbull time server idles due to slow start

Server idles P = minK-1Q times

18-14

TCP Delay Modeling (3)

delay=OR

2 RTT sump=1

P

idleTime p

iquestOR

2 RTTsumk=1

P

[ SR

RTTminus2kminus1 SR

]

iquestOR

2 RTTP [RTT SR

]minus 2Pminus1 SR

[ SRRTT minus2kminus1 SR ]

= idle time after the k th window

SR

RTT= time from when server starts to send segment

until server receives acknowledgement

2kminus1 SR

=time to transmit the kth window

RTT

initia te TCPconnection

requestobject

first w indow= S R

second w indow= 2S R

third w indow= 4S R

fourth w indow= 8S R

com pletetransm issionobject

delivered

tim e atc lient

tim e atserver

18-15

TCP Delay Modeling (4)

Calculation of Q number of idles for infinite-size objectis similar (see text)

Recall K = number of windows that cover object

How do we calculate K

K=min k 20S21 S⋯2kminus1SgeO iquest min k 2021⋯2kminus1geO S

iquest min k 2kminus1geOS

iquest min k kgelog2OS

1

iquest lceil log2OS

1rceil

18-16

Chapter 2 Application layer

21 Principles of network applications

22 Web and HTTP 23 FTP 24 Electronic Mail

diams SMTP POP3 IMAP

25 DNS

26 P2P file sharing 27 Socket programming

with TCP 28 Socket programming

with UDP 29 Building a Web server

18-17

Socket-programming using TCP

Socket a door between application process and end-end-transport protocol (UCP or TCP)

TCP service reliable transfer of bytes from one process to another

process

TCP withbuffers

variables

socket

controlled byapplicationdeveloper

controlled byoperating

system

host orserver

process

TCP withbuffers

variables

socket

controlled byapplicationdeveloper

controlled byoperatingsystem

host orserver

internet

18-18

Socket programming with TCP

Client must contact server server process must first be

running server must have created

socket that welcomes clientrsquos contact

Client contacts server by creating client-local TCP

socket specifying IP address port

number of server process When client creates socket

client TCP establishes connection to server TCP

When contacted by client server TCP creates new socket for server process to communicate with clientdiams allows server to talk with

multiple clientsdiams source port numbers used

to distinguish clients

TCP provides reliable in-order transfer of bytes (ldquopiperdquo) between client and server

application viewpoint

18-19

Clientserver socket interaction TCP

wait for incomingconnection requestconnectionSocket =welcomeSocketaccept()

create socketport=x forincoming requestwelcomeSocket =

ServerSocket(x)

create socketconnect to hostid port=xclientSocket = Socket(hostid x)

closeconnectionSocket

read reply fromclientSocket

closeclientSocket

Server (running on hostid) Client

send request usingclientSocketread request from

connectionSocket

write reply toconnectionSocket

TCP connection setup

18-20ou

tToS

erve

r

to network from network

inFr

omS

erve

r

inFr

omU

ser

keyboard monitor

Process

clientSocket

inputstream

inputstream

outputstream

TCPsocket

Clientprocess

client TCP socket

Stream jargon

A stream is a sequence of characters that flow into or out of a process

An input stream is attached to some input source for the process eg keyboard or socket

An output stream is attached to an output source eg monitor or socket

18-21

Socket programming with TCP

Example client-server app1) client reads line from standard

input (inFromUser stream) sends to server via socket (outToServer stream)

2) server reads line from socket3) server converts line to

uppercase sends back to client4) client reads prints modified line

from socket (inFromServer stream)

18-22

Example Java client (TCP)

import javaio import javanet class TCPClient

public static void main(String argv[]) throws Exception String sentence String modifiedSentence

BufferedReader inFromUser = new BufferedReader(new InputStreamReader(Systemin))

Socket clientSocket = new Socket(hostname 6789)

DataOutputStream outToServer = new DataOutputStream(clientSocketgetOutputStream())

Createinput stream

Create client socket

connect to server

Createoutput stream

attached to socket

18-23

Example Java client (TCP) cont

BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocketgetInputStream()))

sentence = inFromUserreadLine()

outToServerwriteBytes(sentence + n)

modifiedSentence = inFromServerreadLine()

Systemoutprintln(FROM SERVER + modifiedSentence)

clientSocketclose()

Createinput stream

attached to socket

Send lineto server

Read linefrom server

18-24

Example Java server (TCP)

import javaio import javanet

class TCPServer

public static void main(String argv[]) throws Exception String clientSentence String capitalizedSentence

ServerSocket welcomeSocket = new ServerSocket(6789) while(true) Socket connectionSocket = welcomeSocketaccept()

BufferedReader inFromClient = new BufferedReader(new InputStreamReader(connectionSocketgetInputStream()))

Createwelcoming socket

at port 6789

Wait on welcomingsocket for contact

by client

Create inputstream attached

to socket

18-25

Example Java server (TCP) cont

DataOutputStream outToClient = new DataOutputStream(connectionSocketgetOutputStream())

clientSentence = inFromClientreadLine()

capitalizedSentence = clientSentencetoUpperCase() + n

outToClientwriteBytes(capitalizedSentence)

connectionSocketclose()

Read in linefrom socket

Create outputstream attached

to socket

Write out lineto socket

End of while looploop back and wait foranother client connection

18-26

Recap

TCP

diams Throughput

diams Fairness

diams Delay modeling

TCP socket programming

18-27

Next time

NAT

Application layer

diams Intro

diams Web HTTP

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
Page 12: 18-1 Last time □ Fast retransmit ♦ 3 duplicate ACKs □ Flow control ♦ Receiver windows □ Connection management ♦ SYN/SYNACK/ACK, FIN/ACK, TCP states □ Congestion

18-12

TCP Delay Modeling Slow Start (1)

Now suppose window grows according to slow start

Will show that the delay for one object is

Latency=2 RTT OR

P [RTT SR ]minus2Pminus1 S

R

where P is the number of times TCP idles at server

P = m in Q K minus 1

- where Q is the number of times the server idles if the object were of infinite size

- and K is the number of windows that cover the object

18-13

TCP Delay Modeling Slow Start (2)

RTT

initia te TCPconnection

requestobject

first w indow= S R

second w indow= 2S R

third w indow= 4S R

fourth w indow= 8S R

com pletetransm issionobject

delivered

tim e atc lient

tim e atserver

Examplebull OS = 15 segmentsbull K = 4 windowsbull Q = 2bull P = minK-1Q = 2

Server idles P=2 times

Delay componentsbull 2 RTT for connection estab and requestbull OR to transmit objectbull time server idles due to slow start

Server idles P = minK-1Q times

18-14

TCP Delay Modeling (3)

delay=OR

2 RTT sump=1

P

idleTime p

iquestOR

2 RTTsumk=1

P

[ SR

RTTminus2kminus1 SR

]

iquestOR

2 RTTP [RTT SR

]minus 2Pminus1 SR

[ SRRTT minus2kminus1 SR ]

= idle time after the k th window

SR

RTT= time from when server starts to send segment

until server receives acknowledgement

2kminus1 SR

=time to transmit the kth window

RTT

initia te TCPconnection

requestobject

first w indow= S R

second w indow= 2S R

third w indow= 4S R

fourth w indow= 8S R

com pletetransm issionobject

delivered

tim e atc lient

tim e atserver

18-15

TCP Delay Modeling (4)

Calculation of Q number of idles for infinite-size objectis similar (see text)

Recall K = number of windows that cover object

How do we calculate K

K=min k 20S21 S⋯2kminus1SgeO iquest min k 2021⋯2kminus1geO S

iquest min k 2kminus1geOS

iquest min k kgelog2OS

1

iquest lceil log2OS

1rceil

18-16

Chapter 2 Application layer

21 Principles of network applications

22 Web and HTTP 23 FTP 24 Electronic Mail

diams SMTP POP3 IMAP

25 DNS

26 P2P file sharing 27 Socket programming

with TCP 28 Socket programming

with UDP 29 Building a Web server

18-17

Socket-programming using TCP

Socket a door between application process and end-end-transport protocol (UCP or TCP)

TCP service reliable transfer of bytes from one process to another

process

TCP withbuffers

variables

socket

controlled byapplicationdeveloper

controlled byoperating

system

host orserver

process

TCP withbuffers

variables

socket

controlled byapplicationdeveloper

controlled byoperatingsystem

host orserver

internet

18-18

Socket programming with TCP

Client must contact server server process must first be

running server must have created

socket that welcomes clientrsquos contact

Client contacts server by creating client-local TCP

socket specifying IP address port

number of server process When client creates socket

client TCP establishes connection to server TCP

When contacted by client server TCP creates new socket for server process to communicate with clientdiams allows server to talk with

multiple clientsdiams source port numbers used

to distinguish clients

TCP provides reliable in-order transfer of bytes (ldquopiperdquo) between client and server

application viewpoint

18-19

Clientserver socket interaction TCP

wait for incomingconnection requestconnectionSocket =welcomeSocketaccept()

create socketport=x forincoming requestwelcomeSocket =

ServerSocket(x)

create socketconnect to hostid port=xclientSocket = Socket(hostid x)

closeconnectionSocket

read reply fromclientSocket

closeclientSocket

Server (running on hostid) Client

send request usingclientSocketread request from

connectionSocket

write reply toconnectionSocket

TCP connection setup

18-20ou

tToS

erve

r

to network from network

inFr

omS

erve

r

inFr

omU

ser

keyboard monitor

Process

clientSocket

inputstream

inputstream

outputstream

TCPsocket

Clientprocess

client TCP socket

Stream jargon

A stream is a sequence of characters that flow into or out of a process

An input stream is attached to some input source for the process eg keyboard or socket

An output stream is attached to an output source eg monitor or socket

18-21

Socket programming with TCP

Example client-server app1) client reads line from standard

input (inFromUser stream) sends to server via socket (outToServer stream)

2) server reads line from socket3) server converts line to

uppercase sends back to client4) client reads prints modified line

from socket (inFromServer stream)

18-22

Example Java client (TCP)

import javaio import javanet class TCPClient

public static void main(String argv[]) throws Exception String sentence String modifiedSentence

BufferedReader inFromUser = new BufferedReader(new InputStreamReader(Systemin))

Socket clientSocket = new Socket(hostname 6789)

DataOutputStream outToServer = new DataOutputStream(clientSocketgetOutputStream())

Createinput stream

Create client socket

connect to server

Createoutput stream

attached to socket

18-23

Example Java client (TCP) cont

BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocketgetInputStream()))

sentence = inFromUserreadLine()

outToServerwriteBytes(sentence + n)

modifiedSentence = inFromServerreadLine()

Systemoutprintln(FROM SERVER + modifiedSentence)

clientSocketclose()

Createinput stream

attached to socket

Send lineto server

Read linefrom server

18-24

Example Java server (TCP)

import javaio import javanet

class TCPServer

public static void main(String argv[]) throws Exception String clientSentence String capitalizedSentence

ServerSocket welcomeSocket = new ServerSocket(6789) while(true) Socket connectionSocket = welcomeSocketaccept()

BufferedReader inFromClient = new BufferedReader(new InputStreamReader(connectionSocketgetInputStream()))

Createwelcoming socket

at port 6789

Wait on welcomingsocket for contact

by client

Create inputstream attached

to socket

18-25

Example Java server (TCP) cont

DataOutputStream outToClient = new DataOutputStream(connectionSocketgetOutputStream())

clientSentence = inFromClientreadLine()

capitalizedSentence = clientSentencetoUpperCase() + n

outToClientwriteBytes(capitalizedSentence)

connectionSocketclose()

Read in linefrom socket

Create outputstream attached

to socket

Write out lineto socket

End of while looploop back and wait foranother client connection

18-26

Recap

TCP

diams Throughput

diams Fairness

diams Delay modeling

TCP socket programming

18-27

Next time

NAT

Application layer

diams Intro

diams Web HTTP

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
Page 13: 18-1 Last time □ Fast retransmit ♦ 3 duplicate ACKs □ Flow control ♦ Receiver windows □ Connection management ♦ SYN/SYNACK/ACK, FIN/ACK, TCP states □ Congestion

18-13

TCP Delay Modeling Slow Start (2)

RTT

initia te TCPconnection

requestobject

first w indow= S R

second w indow= 2S R

third w indow= 4S R

fourth w indow= 8S R

com pletetransm issionobject

delivered

tim e atc lient

tim e atserver

Examplebull OS = 15 segmentsbull K = 4 windowsbull Q = 2bull P = minK-1Q = 2

Server idles P=2 times

Delay componentsbull 2 RTT for connection estab and requestbull OR to transmit objectbull time server idles due to slow start

Server idles P = minK-1Q times

18-14

TCP Delay Modeling (3)

delay=OR

2 RTT sump=1

P

idleTime p

iquestOR

2 RTTsumk=1

P

[ SR

RTTminus2kminus1 SR

]

iquestOR

2 RTTP [RTT SR

]minus 2Pminus1 SR

[ SRRTT minus2kminus1 SR ]

= idle time after the k th window

SR

RTT= time from when server starts to send segment

until server receives acknowledgement

2kminus1 SR

=time to transmit the kth window

RTT

initia te TCPconnection

requestobject

first w indow= S R

second w indow= 2S R

third w indow= 4S R

fourth w indow= 8S R

com pletetransm issionobject

delivered

tim e atc lient

tim e atserver

18-15

TCP Delay Modeling (4)

Calculation of Q number of idles for infinite-size objectis similar (see text)

Recall K = number of windows that cover object

How do we calculate K

K=min k 20S21 S⋯2kminus1SgeO iquest min k 2021⋯2kminus1geO S

iquest min k 2kminus1geOS

iquest min k kgelog2OS

1

iquest lceil log2OS

1rceil

18-16

Chapter 2 Application layer

21 Principles of network applications

22 Web and HTTP 23 FTP 24 Electronic Mail

diams SMTP POP3 IMAP

25 DNS

26 P2P file sharing 27 Socket programming

with TCP 28 Socket programming

with UDP 29 Building a Web server

18-17

Socket-programming using TCP

Socket a door between application process and end-end-transport protocol (UCP or TCP)

TCP service reliable transfer of bytes from one process to another

process

TCP withbuffers

variables

socket

controlled byapplicationdeveloper

controlled byoperating

system

host orserver

process

TCP withbuffers

variables

socket

controlled byapplicationdeveloper

controlled byoperatingsystem

host orserver

internet

18-18

Socket programming with TCP

Client must contact server server process must first be

running server must have created

socket that welcomes clientrsquos contact

Client contacts server by creating client-local TCP

socket specifying IP address port

number of server process When client creates socket

client TCP establishes connection to server TCP

When contacted by client server TCP creates new socket for server process to communicate with clientdiams allows server to talk with

multiple clientsdiams source port numbers used

to distinguish clients

TCP provides reliable in-order transfer of bytes (ldquopiperdquo) between client and server

application viewpoint

18-19

Clientserver socket interaction TCP

wait for incomingconnection requestconnectionSocket =welcomeSocketaccept()

create socketport=x forincoming requestwelcomeSocket =

ServerSocket(x)

create socketconnect to hostid port=xclientSocket = Socket(hostid x)

closeconnectionSocket

read reply fromclientSocket

closeclientSocket

Server (running on hostid) Client

send request usingclientSocketread request from

connectionSocket

write reply toconnectionSocket

TCP connection setup

18-20ou

tToS

erve

r

to network from network

inFr

omS

erve

r

inFr

omU

ser

keyboard monitor

Process

clientSocket

inputstream

inputstream

outputstream

TCPsocket

Clientprocess

client TCP socket

Stream jargon

A stream is a sequence of characters that flow into or out of a process

An input stream is attached to some input source for the process eg keyboard or socket

An output stream is attached to an output source eg monitor or socket

18-21

Socket programming with TCP

Example client-server app1) client reads line from standard

input (inFromUser stream) sends to server via socket (outToServer stream)

2) server reads line from socket3) server converts line to

uppercase sends back to client4) client reads prints modified line

from socket (inFromServer stream)

18-22

Example Java client (TCP)

import javaio import javanet class TCPClient

public static void main(String argv[]) throws Exception String sentence String modifiedSentence

BufferedReader inFromUser = new BufferedReader(new InputStreamReader(Systemin))

Socket clientSocket = new Socket(hostname 6789)

DataOutputStream outToServer = new DataOutputStream(clientSocketgetOutputStream())

Createinput stream

Create client socket

connect to server

Createoutput stream

attached to socket

18-23

Example Java client (TCP) cont

BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocketgetInputStream()))

sentence = inFromUserreadLine()

outToServerwriteBytes(sentence + n)

modifiedSentence = inFromServerreadLine()

Systemoutprintln(FROM SERVER + modifiedSentence)

clientSocketclose()

Createinput stream

attached to socket

Send lineto server

Read linefrom server

18-24

Example Java server (TCP)

import javaio import javanet

class TCPServer

public static void main(String argv[]) throws Exception String clientSentence String capitalizedSentence

ServerSocket welcomeSocket = new ServerSocket(6789) while(true) Socket connectionSocket = welcomeSocketaccept()

BufferedReader inFromClient = new BufferedReader(new InputStreamReader(connectionSocketgetInputStream()))

Createwelcoming socket

at port 6789

Wait on welcomingsocket for contact

by client

Create inputstream attached

to socket

18-25

Example Java server (TCP) cont

DataOutputStream outToClient = new DataOutputStream(connectionSocketgetOutputStream())

clientSentence = inFromClientreadLine()

capitalizedSentence = clientSentencetoUpperCase() + n

outToClientwriteBytes(capitalizedSentence)

connectionSocketclose()

Read in linefrom socket

Create outputstream attached

to socket

Write out lineto socket

End of while looploop back and wait foranother client connection

18-26

Recap

TCP

diams Throughput

diams Fairness

diams Delay modeling

TCP socket programming

18-27

Next time

NAT

Application layer

diams Intro

diams Web HTTP

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
Page 14: 18-1 Last time □ Fast retransmit ♦ 3 duplicate ACKs □ Flow control ♦ Receiver windows □ Connection management ♦ SYN/SYNACK/ACK, FIN/ACK, TCP states □ Congestion

18-14

TCP Delay Modeling (3)

delay=OR

2 RTT sump=1

P

idleTime p

iquestOR

2 RTTsumk=1

P

[ SR

RTTminus2kminus1 SR

]

iquestOR

2 RTTP [RTT SR

]minus 2Pminus1 SR

[ SRRTT minus2kminus1 SR ]

= idle time after the k th window

SR

RTT= time from when server starts to send segment

until server receives acknowledgement

2kminus1 SR

=time to transmit the kth window

RTT

initia te TCPconnection

requestobject

first w indow= S R

second w indow= 2S R

third w indow= 4S R

fourth w indow= 8S R

com pletetransm issionobject

delivered

tim e atc lient

tim e atserver

18-15

TCP Delay Modeling (4)

Calculation of Q number of idles for infinite-size objectis similar (see text)

Recall K = number of windows that cover object

How do we calculate K

K=min k 20S21 S⋯2kminus1SgeO iquest min k 2021⋯2kminus1geO S

iquest min k 2kminus1geOS

iquest min k kgelog2OS

1

iquest lceil log2OS

1rceil

18-16

Chapter 2 Application layer

21 Principles of network applications

22 Web and HTTP 23 FTP 24 Electronic Mail

diams SMTP POP3 IMAP

25 DNS

26 P2P file sharing 27 Socket programming

with TCP 28 Socket programming

with UDP 29 Building a Web server

18-17

Socket-programming using TCP

Socket a door between application process and end-end-transport protocol (UCP or TCP)

TCP service reliable transfer of bytes from one process to another

process

TCP withbuffers

variables

socket

controlled byapplicationdeveloper

controlled byoperating

system

host orserver

process

TCP withbuffers

variables

socket

controlled byapplicationdeveloper

controlled byoperatingsystem

host orserver

internet

18-18

Socket programming with TCP

Client must contact server server process must first be

running server must have created

socket that welcomes clientrsquos contact

Client contacts server by creating client-local TCP

socket specifying IP address port

number of server process When client creates socket

client TCP establishes connection to server TCP

When contacted by client server TCP creates new socket for server process to communicate with clientdiams allows server to talk with

multiple clientsdiams source port numbers used

to distinguish clients

TCP provides reliable in-order transfer of bytes (ldquopiperdquo) between client and server

application viewpoint

18-19

Clientserver socket interaction TCP

wait for incomingconnection requestconnectionSocket =welcomeSocketaccept()

create socketport=x forincoming requestwelcomeSocket =

ServerSocket(x)

create socketconnect to hostid port=xclientSocket = Socket(hostid x)

closeconnectionSocket

read reply fromclientSocket

closeclientSocket

Server (running on hostid) Client

send request usingclientSocketread request from

connectionSocket

write reply toconnectionSocket

TCP connection setup

18-20ou

tToS

erve

r

to network from network

inFr

omS

erve

r

inFr

omU

ser

keyboard monitor

Process

clientSocket

inputstream

inputstream

outputstream

TCPsocket

Clientprocess

client TCP socket

Stream jargon

A stream is a sequence of characters that flow into or out of a process

An input stream is attached to some input source for the process eg keyboard or socket

An output stream is attached to an output source eg monitor or socket

18-21

Socket programming with TCP

Example client-server app1) client reads line from standard

input (inFromUser stream) sends to server via socket (outToServer stream)

2) server reads line from socket3) server converts line to

uppercase sends back to client4) client reads prints modified line

from socket (inFromServer stream)

18-22

Example Java client (TCP)

import javaio import javanet class TCPClient

public static void main(String argv[]) throws Exception String sentence String modifiedSentence

BufferedReader inFromUser = new BufferedReader(new InputStreamReader(Systemin))

Socket clientSocket = new Socket(hostname 6789)

DataOutputStream outToServer = new DataOutputStream(clientSocketgetOutputStream())

Createinput stream

Create client socket

connect to server

Createoutput stream

attached to socket

18-23

Example Java client (TCP) cont

BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocketgetInputStream()))

sentence = inFromUserreadLine()

outToServerwriteBytes(sentence + n)

modifiedSentence = inFromServerreadLine()

Systemoutprintln(FROM SERVER + modifiedSentence)

clientSocketclose()

Createinput stream

attached to socket

Send lineto server

Read linefrom server

18-24

Example Java server (TCP)

import javaio import javanet

class TCPServer

public static void main(String argv[]) throws Exception String clientSentence String capitalizedSentence

ServerSocket welcomeSocket = new ServerSocket(6789) while(true) Socket connectionSocket = welcomeSocketaccept()

BufferedReader inFromClient = new BufferedReader(new InputStreamReader(connectionSocketgetInputStream()))

Createwelcoming socket

at port 6789

Wait on welcomingsocket for contact

by client

Create inputstream attached

to socket

18-25

Example Java server (TCP) cont

DataOutputStream outToClient = new DataOutputStream(connectionSocketgetOutputStream())

clientSentence = inFromClientreadLine()

capitalizedSentence = clientSentencetoUpperCase() + n

outToClientwriteBytes(capitalizedSentence)

connectionSocketclose()

Read in linefrom socket

Create outputstream attached

to socket

Write out lineto socket

End of while looploop back and wait foranother client connection

18-26

Recap

TCP

diams Throughput

diams Fairness

diams Delay modeling

TCP socket programming

18-27

Next time

NAT

Application layer

diams Intro

diams Web HTTP

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
Page 15: 18-1 Last time □ Fast retransmit ♦ 3 duplicate ACKs □ Flow control ♦ Receiver windows □ Connection management ♦ SYN/SYNACK/ACK, FIN/ACK, TCP states □ Congestion

18-15

TCP Delay Modeling (4)

Calculation of Q number of idles for infinite-size objectis similar (see text)

Recall K = number of windows that cover object

How do we calculate K

K=min k 20S21 S⋯2kminus1SgeO iquest min k 2021⋯2kminus1geO S

iquest min k 2kminus1geOS

iquest min k kgelog2OS

1

iquest lceil log2OS

1rceil

18-16

Chapter 2 Application layer

21 Principles of network applications

22 Web and HTTP 23 FTP 24 Electronic Mail

diams SMTP POP3 IMAP

25 DNS

26 P2P file sharing 27 Socket programming

with TCP 28 Socket programming

with UDP 29 Building a Web server

18-17

Socket-programming using TCP

Socket a door between application process and end-end-transport protocol (UCP or TCP)

TCP service reliable transfer of bytes from one process to another

process

TCP withbuffers

variables

socket

controlled byapplicationdeveloper

controlled byoperating

system

host orserver

process

TCP withbuffers

variables

socket

controlled byapplicationdeveloper

controlled byoperatingsystem

host orserver

internet

18-18

Socket programming with TCP

Client must contact server server process must first be

running server must have created

socket that welcomes clientrsquos contact

Client contacts server by creating client-local TCP

socket specifying IP address port

number of server process When client creates socket

client TCP establishes connection to server TCP

When contacted by client server TCP creates new socket for server process to communicate with clientdiams allows server to talk with

multiple clientsdiams source port numbers used

to distinguish clients

TCP provides reliable in-order transfer of bytes (ldquopiperdquo) between client and server

application viewpoint

18-19

Clientserver socket interaction TCP

wait for incomingconnection requestconnectionSocket =welcomeSocketaccept()

create socketport=x forincoming requestwelcomeSocket =

ServerSocket(x)

create socketconnect to hostid port=xclientSocket = Socket(hostid x)

closeconnectionSocket

read reply fromclientSocket

closeclientSocket

Server (running on hostid) Client

send request usingclientSocketread request from

connectionSocket

write reply toconnectionSocket

TCP connection setup

18-20ou

tToS

erve

r

to network from network

inFr

omS

erve

r

inFr

omU

ser

keyboard monitor

Process

clientSocket

inputstream

inputstream

outputstream

TCPsocket

Clientprocess

client TCP socket

Stream jargon

A stream is a sequence of characters that flow into or out of a process

An input stream is attached to some input source for the process eg keyboard or socket

An output stream is attached to an output source eg monitor or socket

18-21

Socket programming with TCP

Example client-server app1) client reads line from standard

input (inFromUser stream) sends to server via socket (outToServer stream)

2) server reads line from socket3) server converts line to

uppercase sends back to client4) client reads prints modified line

from socket (inFromServer stream)

18-22

Example Java client (TCP)

import javaio import javanet class TCPClient

public static void main(String argv[]) throws Exception String sentence String modifiedSentence

BufferedReader inFromUser = new BufferedReader(new InputStreamReader(Systemin))

Socket clientSocket = new Socket(hostname 6789)

DataOutputStream outToServer = new DataOutputStream(clientSocketgetOutputStream())

Createinput stream

Create client socket

connect to server

Createoutput stream

attached to socket

18-23

Example Java client (TCP) cont

BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocketgetInputStream()))

sentence = inFromUserreadLine()

outToServerwriteBytes(sentence + n)

modifiedSentence = inFromServerreadLine()

Systemoutprintln(FROM SERVER + modifiedSentence)

clientSocketclose()

Createinput stream

attached to socket

Send lineto server

Read linefrom server

18-24

Example Java server (TCP)

import javaio import javanet

class TCPServer

public static void main(String argv[]) throws Exception String clientSentence String capitalizedSentence

ServerSocket welcomeSocket = new ServerSocket(6789) while(true) Socket connectionSocket = welcomeSocketaccept()

BufferedReader inFromClient = new BufferedReader(new InputStreamReader(connectionSocketgetInputStream()))

Createwelcoming socket

at port 6789

Wait on welcomingsocket for contact

by client

Create inputstream attached

to socket

18-25

Example Java server (TCP) cont

DataOutputStream outToClient = new DataOutputStream(connectionSocketgetOutputStream())

clientSentence = inFromClientreadLine()

capitalizedSentence = clientSentencetoUpperCase() + n

outToClientwriteBytes(capitalizedSentence)

connectionSocketclose()

Read in linefrom socket

Create outputstream attached

to socket

Write out lineto socket

End of while looploop back and wait foranother client connection

18-26

Recap

TCP

diams Throughput

diams Fairness

diams Delay modeling

TCP socket programming

18-27

Next time

NAT

Application layer

diams Intro

diams Web HTTP

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
Page 16: 18-1 Last time □ Fast retransmit ♦ 3 duplicate ACKs □ Flow control ♦ Receiver windows □ Connection management ♦ SYN/SYNACK/ACK, FIN/ACK, TCP states □ Congestion

18-16

Chapter 2 Application layer

21 Principles of network applications

22 Web and HTTP 23 FTP 24 Electronic Mail

diams SMTP POP3 IMAP

25 DNS

26 P2P file sharing 27 Socket programming

with TCP 28 Socket programming

with UDP 29 Building a Web server

18-17

Socket-programming using TCP

Socket a door between application process and end-end-transport protocol (UCP or TCP)

TCP service reliable transfer of bytes from one process to another

process

TCP withbuffers

variables

socket

controlled byapplicationdeveloper

controlled byoperating

system

host orserver

process

TCP withbuffers

variables

socket

controlled byapplicationdeveloper

controlled byoperatingsystem

host orserver

internet

18-18

Socket programming with TCP

Client must contact server server process must first be

running server must have created

socket that welcomes clientrsquos contact

Client contacts server by creating client-local TCP

socket specifying IP address port

number of server process When client creates socket

client TCP establishes connection to server TCP

When contacted by client server TCP creates new socket for server process to communicate with clientdiams allows server to talk with

multiple clientsdiams source port numbers used

to distinguish clients

TCP provides reliable in-order transfer of bytes (ldquopiperdquo) between client and server

application viewpoint

18-19

Clientserver socket interaction TCP

wait for incomingconnection requestconnectionSocket =welcomeSocketaccept()

create socketport=x forincoming requestwelcomeSocket =

ServerSocket(x)

create socketconnect to hostid port=xclientSocket = Socket(hostid x)

closeconnectionSocket

read reply fromclientSocket

closeclientSocket

Server (running on hostid) Client

send request usingclientSocketread request from

connectionSocket

write reply toconnectionSocket

TCP connection setup

18-20ou

tToS

erve

r

to network from network

inFr

omS

erve

r

inFr

omU

ser

keyboard monitor

Process

clientSocket

inputstream

inputstream

outputstream

TCPsocket

Clientprocess

client TCP socket

Stream jargon

A stream is a sequence of characters that flow into or out of a process

An input stream is attached to some input source for the process eg keyboard or socket

An output stream is attached to an output source eg monitor or socket

18-21

Socket programming with TCP

Example client-server app1) client reads line from standard

input (inFromUser stream) sends to server via socket (outToServer stream)

2) server reads line from socket3) server converts line to

uppercase sends back to client4) client reads prints modified line

from socket (inFromServer stream)

18-22

Example Java client (TCP)

import javaio import javanet class TCPClient

public static void main(String argv[]) throws Exception String sentence String modifiedSentence

BufferedReader inFromUser = new BufferedReader(new InputStreamReader(Systemin))

Socket clientSocket = new Socket(hostname 6789)

DataOutputStream outToServer = new DataOutputStream(clientSocketgetOutputStream())

Createinput stream

Create client socket

connect to server

Createoutput stream

attached to socket

18-23

Example Java client (TCP) cont

BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocketgetInputStream()))

sentence = inFromUserreadLine()

outToServerwriteBytes(sentence + n)

modifiedSentence = inFromServerreadLine()

Systemoutprintln(FROM SERVER + modifiedSentence)

clientSocketclose()

Createinput stream

attached to socket

Send lineto server

Read linefrom server

18-24

Example Java server (TCP)

import javaio import javanet

class TCPServer

public static void main(String argv[]) throws Exception String clientSentence String capitalizedSentence

ServerSocket welcomeSocket = new ServerSocket(6789) while(true) Socket connectionSocket = welcomeSocketaccept()

BufferedReader inFromClient = new BufferedReader(new InputStreamReader(connectionSocketgetInputStream()))

Createwelcoming socket

at port 6789

Wait on welcomingsocket for contact

by client

Create inputstream attached

to socket

18-25

Example Java server (TCP) cont

DataOutputStream outToClient = new DataOutputStream(connectionSocketgetOutputStream())

clientSentence = inFromClientreadLine()

capitalizedSentence = clientSentencetoUpperCase() + n

outToClientwriteBytes(capitalizedSentence)

connectionSocketclose()

Read in linefrom socket

Create outputstream attached

to socket

Write out lineto socket

End of while looploop back and wait foranother client connection

18-26

Recap

TCP

diams Throughput

diams Fairness

diams Delay modeling

TCP socket programming

18-27

Next time

NAT

Application layer

diams Intro

diams Web HTTP

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
Page 17: 18-1 Last time □ Fast retransmit ♦ 3 duplicate ACKs □ Flow control ♦ Receiver windows □ Connection management ♦ SYN/SYNACK/ACK, FIN/ACK, TCP states □ Congestion

18-17

Socket-programming using TCP

Socket a door between application process and end-end-transport protocol (UCP or TCP)

TCP service reliable transfer of bytes from one process to another

process

TCP withbuffers

variables

socket

controlled byapplicationdeveloper

controlled byoperating

system

host orserver

process

TCP withbuffers

variables

socket

controlled byapplicationdeveloper

controlled byoperatingsystem

host orserver

internet

18-18

Socket programming with TCP

Client must contact server server process must first be

running server must have created

socket that welcomes clientrsquos contact

Client contacts server by creating client-local TCP

socket specifying IP address port

number of server process When client creates socket

client TCP establishes connection to server TCP

When contacted by client server TCP creates new socket for server process to communicate with clientdiams allows server to talk with

multiple clientsdiams source port numbers used

to distinguish clients

TCP provides reliable in-order transfer of bytes (ldquopiperdquo) between client and server

application viewpoint

18-19

Clientserver socket interaction TCP

wait for incomingconnection requestconnectionSocket =welcomeSocketaccept()

create socketport=x forincoming requestwelcomeSocket =

ServerSocket(x)

create socketconnect to hostid port=xclientSocket = Socket(hostid x)

closeconnectionSocket

read reply fromclientSocket

closeclientSocket

Server (running on hostid) Client

send request usingclientSocketread request from

connectionSocket

write reply toconnectionSocket

TCP connection setup

18-20ou

tToS

erve

r

to network from network

inFr

omS

erve

r

inFr

omU

ser

keyboard monitor

Process

clientSocket

inputstream

inputstream

outputstream

TCPsocket

Clientprocess

client TCP socket

Stream jargon

A stream is a sequence of characters that flow into or out of a process

An input stream is attached to some input source for the process eg keyboard or socket

An output stream is attached to an output source eg monitor or socket

18-21

Socket programming with TCP

Example client-server app1) client reads line from standard

input (inFromUser stream) sends to server via socket (outToServer stream)

2) server reads line from socket3) server converts line to

uppercase sends back to client4) client reads prints modified line

from socket (inFromServer stream)

18-22

Example Java client (TCP)

import javaio import javanet class TCPClient

public static void main(String argv[]) throws Exception String sentence String modifiedSentence

BufferedReader inFromUser = new BufferedReader(new InputStreamReader(Systemin))

Socket clientSocket = new Socket(hostname 6789)

DataOutputStream outToServer = new DataOutputStream(clientSocketgetOutputStream())

Createinput stream

Create client socket

connect to server

Createoutput stream

attached to socket

18-23

Example Java client (TCP) cont

BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocketgetInputStream()))

sentence = inFromUserreadLine()

outToServerwriteBytes(sentence + n)

modifiedSentence = inFromServerreadLine()

Systemoutprintln(FROM SERVER + modifiedSentence)

clientSocketclose()

Createinput stream

attached to socket

Send lineto server

Read linefrom server

18-24

Example Java server (TCP)

import javaio import javanet

class TCPServer

public static void main(String argv[]) throws Exception String clientSentence String capitalizedSentence

ServerSocket welcomeSocket = new ServerSocket(6789) while(true) Socket connectionSocket = welcomeSocketaccept()

BufferedReader inFromClient = new BufferedReader(new InputStreamReader(connectionSocketgetInputStream()))

Createwelcoming socket

at port 6789

Wait on welcomingsocket for contact

by client

Create inputstream attached

to socket

18-25

Example Java server (TCP) cont

DataOutputStream outToClient = new DataOutputStream(connectionSocketgetOutputStream())

clientSentence = inFromClientreadLine()

capitalizedSentence = clientSentencetoUpperCase() + n

outToClientwriteBytes(capitalizedSentence)

connectionSocketclose()

Read in linefrom socket

Create outputstream attached

to socket

Write out lineto socket

End of while looploop back and wait foranother client connection

18-26

Recap

TCP

diams Throughput

diams Fairness

diams Delay modeling

TCP socket programming

18-27

Next time

NAT

Application layer

diams Intro

diams Web HTTP

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
Page 18: 18-1 Last time □ Fast retransmit ♦ 3 duplicate ACKs □ Flow control ♦ Receiver windows □ Connection management ♦ SYN/SYNACK/ACK, FIN/ACK, TCP states □ Congestion

18-18

Socket programming with TCP

Client must contact server server process must first be

running server must have created

socket that welcomes clientrsquos contact

Client contacts server by creating client-local TCP

socket specifying IP address port

number of server process When client creates socket

client TCP establishes connection to server TCP

When contacted by client server TCP creates new socket for server process to communicate with clientdiams allows server to talk with

multiple clientsdiams source port numbers used

to distinguish clients

TCP provides reliable in-order transfer of bytes (ldquopiperdquo) between client and server

application viewpoint

18-19

Clientserver socket interaction TCP

wait for incomingconnection requestconnectionSocket =welcomeSocketaccept()

create socketport=x forincoming requestwelcomeSocket =

ServerSocket(x)

create socketconnect to hostid port=xclientSocket = Socket(hostid x)

closeconnectionSocket

read reply fromclientSocket

closeclientSocket

Server (running on hostid) Client

send request usingclientSocketread request from

connectionSocket

write reply toconnectionSocket

TCP connection setup

18-20ou

tToS

erve

r

to network from network

inFr

omS

erve

r

inFr

omU

ser

keyboard monitor

Process

clientSocket

inputstream

inputstream

outputstream

TCPsocket

Clientprocess

client TCP socket

Stream jargon

A stream is a sequence of characters that flow into or out of a process

An input stream is attached to some input source for the process eg keyboard or socket

An output stream is attached to an output source eg monitor or socket

18-21

Socket programming with TCP

Example client-server app1) client reads line from standard

input (inFromUser stream) sends to server via socket (outToServer stream)

2) server reads line from socket3) server converts line to

uppercase sends back to client4) client reads prints modified line

from socket (inFromServer stream)

18-22

Example Java client (TCP)

import javaio import javanet class TCPClient

public static void main(String argv[]) throws Exception String sentence String modifiedSentence

BufferedReader inFromUser = new BufferedReader(new InputStreamReader(Systemin))

Socket clientSocket = new Socket(hostname 6789)

DataOutputStream outToServer = new DataOutputStream(clientSocketgetOutputStream())

Createinput stream

Create client socket

connect to server

Createoutput stream

attached to socket

18-23

Example Java client (TCP) cont

BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocketgetInputStream()))

sentence = inFromUserreadLine()

outToServerwriteBytes(sentence + n)

modifiedSentence = inFromServerreadLine()

Systemoutprintln(FROM SERVER + modifiedSentence)

clientSocketclose()

Createinput stream

attached to socket

Send lineto server

Read linefrom server

18-24

Example Java server (TCP)

import javaio import javanet

class TCPServer

public static void main(String argv[]) throws Exception String clientSentence String capitalizedSentence

ServerSocket welcomeSocket = new ServerSocket(6789) while(true) Socket connectionSocket = welcomeSocketaccept()

BufferedReader inFromClient = new BufferedReader(new InputStreamReader(connectionSocketgetInputStream()))

Createwelcoming socket

at port 6789

Wait on welcomingsocket for contact

by client

Create inputstream attached

to socket

18-25

Example Java server (TCP) cont

DataOutputStream outToClient = new DataOutputStream(connectionSocketgetOutputStream())

clientSentence = inFromClientreadLine()

capitalizedSentence = clientSentencetoUpperCase() + n

outToClientwriteBytes(capitalizedSentence)

connectionSocketclose()

Read in linefrom socket

Create outputstream attached

to socket

Write out lineto socket

End of while looploop back and wait foranother client connection

18-26

Recap

TCP

diams Throughput

diams Fairness

diams Delay modeling

TCP socket programming

18-27

Next time

NAT

Application layer

diams Intro

diams Web HTTP

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
Page 19: 18-1 Last time □ Fast retransmit ♦ 3 duplicate ACKs □ Flow control ♦ Receiver windows □ Connection management ♦ SYN/SYNACK/ACK, FIN/ACK, TCP states □ Congestion

18-19

Clientserver socket interaction TCP

wait for incomingconnection requestconnectionSocket =welcomeSocketaccept()

create socketport=x forincoming requestwelcomeSocket =

ServerSocket(x)

create socketconnect to hostid port=xclientSocket = Socket(hostid x)

closeconnectionSocket

read reply fromclientSocket

closeclientSocket

Server (running on hostid) Client

send request usingclientSocketread request from

connectionSocket

write reply toconnectionSocket

TCP connection setup

18-20ou

tToS

erve

r

to network from network

inFr

omS

erve

r

inFr

omU

ser

keyboard monitor

Process

clientSocket

inputstream

inputstream

outputstream

TCPsocket

Clientprocess

client TCP socket

Stream jargon

A stream is a sequence of characters that flow into or out of a process

An input stream is attached to some input source for the process eg keyboard or socket

An output stream is attached to an output source eg monitor or socket

18-21

Socket programming with TCP

Example client-server app1) client reads line from standard

input (inFromUser stream) sends to server via socket (outToServer stream)

2) server reads line from socket3) server converts line to

uppercase sends back to client4) client reads prints modified line

from socket (inFromServer stream)

18-22

Example Java client (TCP)

import javaio import javanet class TCPClient

public static void main(String argv[]) throws Exception String sentence String modifiedSentence

BufferedReader inFromUser = new BufferedReader(new InputStreamReader(Systemin))

Socket clientSocket = new Socket(hostname 6789)

DataOutputStream outToServer = new DataOutputStream(clientSocketgetOutputStream())

Createinput stream

Create client socket

connect to server

Createoutput stream

attached to socket

18-23

Example Java client (TCP) cont

BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocketgetInputStream()))

sentence = inFromUserreadLine()

outToServerwriteBytes(sentence + n)

modifiedSentence = inFromServerreadLine()

Systemoutprintln(FROM SERVER + modifiedSentence)

clientSocketclose()

Createinput stream

attached to socket

Send lineto server

Read linefrom server

18-24

Example Java server (TCP)

import javaio import javanet

class TCPServer

public static void main(String argv[]) throws Exception String clientSentence String capitalizedSentence

ServerSocket welcomeSocket = new ServerSocket(6789) while(true) Socket connectionSocket = welcomeSocketaccept()

BufferedReader inFromClient = new BufferedReader(new InputStreamReader(connectionSocketgetInputStream()))

Createwelcoming socket

at port 6789

Wait on welcomingsocket for contact

by client

Create inputstream attached

to socket

18-25

Example Java server (TCP) cont

DataOutputStream outToClient = new DataOutputStream(connectionSocketgetOutputStream())

clientSentence = inFromClientreadLine()

capitalizedSentence = clientSentencetoUpperCase() + n

outToClientwriteBytes(capitalizedSentence)

connectionSocketclose()

Read in linefrom socket

Create outputstream attached

to socket

Write out lineto socket

End of while looploop back and wait foranother client connection

18-26

Recap

TCP

diams Throughput

diams Fairness

diams Delay modeling

TCP socket programming

18-27

Next time

NAT

Application layer

diams Intro

diams Web HTTP

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
Page 20: 18-1 Last time □ Fast retransmit ♦ 3 duplicate ACKs □ Flow control ♦ Receiver windows □ Connection management ♦ SYN/SYNACK/ACK, FIN/ACK, TCP states □ Congestion

18-20ou

tToS

erve

r

to network from network

inFr

omS

erve

r

inFr

omU

ser

keyboard monitor

Process

clientSocket

inputstream

inputstream

outputstream

TCPsocket

Clientprocess

client TCP socket

Stream jargon

A stream is a sequence of characters that flow into or out of a process

An input stream is attached to some input source for the process eg keyboard or socket

An output stream is attached to an output source eg monitor or socket

18-21

Socket programming with TCP

Example client-server app1) client reads line from standard

input (inFromUser stream) sends to server via socket (outToServer stream)

2) server reads line from socket3) server converts line to

uppercase sends back to client4) client reads prints modified line

from socket (inFromServer stream)

18-22

Example Java client (TCP)

import javaio import javanet class TCPClient

public static void main(String argv[]) throws Exception String sentence String modifiedSentence

BufferedReader inFromUser = new BufferedReader(new InputStreamReader(Systemin))

Socket clientSocket = new Socket(hostname 6789)

DataOutputStream outToServer = new DataOutputStream(clientSocketgetOutputStream())

Createinput stream

Create client socket

connect to server

Createoutput stream

attached to socket

18-23

Example Java client (TCP) cont

BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocketgetInputStream()))

sentence = inFromUserreadLine()

outToServerwriteBytes(sentence + n)

modifiedSentence = inFromServerreadLine()

Systemoutprintln(FROM SERVER + modifiedSentence)

clientSocketclose()

Createinput stream

attached to socket

Send lineto server

Read linefrom server

18-24

Example Java server (TCP)

import javaio import javanet

class TCPServer

public static void main(String argv[]) throws Exception String clientSentence String capitalizedSentence

ServerSocket welcomeSocket = new ServerSocket(6789) while(true) Socket connectionSocket = welcomeSocketaccept()

BufferedReader inFromClient = new BufferedReader(new InputStreamReader(connectionSocketgetInputStream()))

Createwelcoming socket

at port 6789

Wait on welcomingsocket for contact

by client

Create inputstream attached

to socket

18-25

Example Java server (TCP) cont

DataOutputStream outToClient = new DataOutputStream(connectionSocketgetOutputStream())

clientSentence = inFromClientreadLine()

capitalizedSentence = clientSentencetoUpperCase() + n

outToClientwriteBytes(capitalizedSentence)

connectionSocketclose()

Read in linefrom socket

Create outputstream attached

to socket

Write out lineto socket

End of while looploop back and wait foranother client connection

18-26

Recap

TCP

diams Throughput

diams Fairness

diams Delay modeling

TCP socket programming

18-27

Next time

NAT

Application layer

diams Intro

diams Web HTTP

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
Page 21: 18-1 Last time □ Fast retransmit ♦ 3 duplicate ACKs □ Flow control ♦ Receiver windows □ Connection management ♦ SYN/SYNACK/ACK, FIN/ACK, TCP states □ Congestion

18-21

Socket programming with TCP

Example client-server app1) client reads line from standard

input (inFromUser stream) sends to server via socket (outToServer stream)

2) server reads line from socket3) server converts line to

uppercase sends back to client4) client reads prints modified line

from socket (inFromServer stream)

18-22

Example Java client (TCP)

import javaio import javanet class TCPClient

public static void main(String argv[]) throws Exception String sentence String modifiedSentence

BufferedReader inFromUser = new BufferedReader(new InputStreamReader(Systemin))

Socket clientSocket = new Socket(hostname 6789)

DataOutputStream outToServer = new DataOutputStream(clientSocketgetOutputStream())

Createinput stream

Create client socket

connect to server

Createoutput stream

attached to socket

18-23

Example Java client (TCP) cont

BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocketgetInputStream()))

sentence = inFromUserreadLine()

outToServerwriteBytes(sentence + n)

modifiedSentence = inFromServerreadLine()

Systemoutprintln(FROM SERVER + modifiedSentence)

clientSocketclose()

Createinput stream

attached to socket

Send lineto server

Read linefrom server

18-24

Example Java server (TCP)

import javaio import javanet

class TCPServer

public static void main(String argv[]) throws Exception String clientSentence String capitalizedSentence

ServerSocket welcomeSocket = new ServerSocket(6789) while(true) Socket connectionSocket = welcomeSocketaccept()

BufferedReader inFromClient = new BufferedReader(new InputStreamReader(connectionSocketgetInputStream()))

Createwelcoming socket

at port 6789

Wait on welcomingsocket for contact

by client

Create inputstream attached

to socket

18-25

Example Java server (TCP) cont

DataOutputStream outToClient = new DataOutputStream(connectionSocketgetOutputStream())

clientSentence = inFromClientreadLine()

capitalizedSentence = clientSentencetoUpperCase() + n

outToClientwriteBytes(capitalizedSentence)

connectionSocketclose()

Read in linefrom socket

Create outputstream attached

to socket

Write out lineto socket

End of while looploop back and wait foranother client connection

18-26

Recap

TCP

diams Throughput

diams Fairness

diams Delay modeling

TCP socket programming

18-27

Next time

NAT

Application layer

diams Intro

diams Web HTTP

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
Page 22: 18-1 Last time □ Fast retransmit ♦ 3 duplicate ACKs □ Flow control ♦ Receiver windows □ Connection management ♦ SYN/SYNACK/ACK, FIN/ACK, TCP states □ Congestion

18-22

Example Java client (TCP)

import javaio import javanet class TCPClient

public static void main(String argv[]) throws Exception String sentence String modifiedSentence

BufferedReader inFromUser = new BufferedReader(new InputStreamReader(Systemin))

Socket clientSocket = new Socket(hostname 6789)

DataOutputStream outToServer = new DataOutputStream(clientSocketgetOutputStream())

Createinput stream

Create client socket

connect to server

Createoutput stream

attached to socket

18-23

Example Java client (TCP) cont

BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocketgetInputStream()))

sentence = inFromUserreadLine()

outToServerwriteBytes(sentence + n)

modifiedSentence = inFromServerreadLine()

Systemoutprintln(FROM SERVER + modifiedSentence)

clientSocketclose()

Createinput stream

attached to socket

Send lineto server

Read linefrom server

18-24

Example Java server (TCP)

import javaio import javanet

class TCPServer

public static void main(String argv[]) throws Exception String clientSentence String capitalizedSentence

ServerSocket welcomeSocket = new ServerSocket(6789) while(true) Socket connectionSocket = welcomeSocketaccept()

BufferedReader inFromClient = new BufferedReader(new InputStreamReader(connectionSocketgetInputStream()))

Createwelcoming socket

at port 6789

Wait on welcomingsocket for contact

by client

Create inputstream attached

to socket

18-25

Example Java server (TCP) cont

DataOutputStream outToClient = new DataOutputStream(connectionSocketgetOutputStream())

clientSentence = inFromClientreadLine()

capitalizedSentence = clientSentencetoUpperCase() + n

outToClientwriteBytes(capitalizedSentence)

connectionSocketclose()

Read in linefrom socket

Create outputstream attached

to socket

Write out lineto socket

End of while looploop back and wait foranother client connection

18-26

Recap

TCP

diams Throughput

diams Fairness

diams Delay modeling

TCP socket programming

18-27

Next time

NAT

Application layer

diams Intro

diams Web HTTP

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
Page 23: 18-1 Last time □ Fast retransmit ♦ 3 duplicate ACKs □ Flow control ♦ Receiver windows □ Connection management ♦ SYN/SYNACK/ACK, FIN/ACK, TCP states □ Congestion

18-23

Example Java client (TCP) cont

BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocketgetInputStream()))

sentence = inFromUserreadLine()

outToServerwriteBytes(sentence + n)

modifiedSentence = inFromServerreadLine()

Systemoutprintln(FROM SERVER + modifiedSentence)

clientSocketclose()

Createinput stream

attached to socket

Send lineto server

Read linefrom server

18-24

Example Java server (TCP)

import javaio import javanet

class TCPServer

public static void main(String argv[]) throws Exception String clientSentence String capitalizedSentence

ServerSocket welcomeSocket = new ServerSocket(6789) while(true) Socket connectionSocket = welcomeSocketaccept()

BufferedReader inFromClient = new BufferedReader(new InputStreamReader(connectionSocketgetInputStream()))

Createwelcoming socket

at port 6789

Wait on welcomingsocket for contact

by client

Create inputstream attached

to socket

18-25

Example Java server (TCP) cont

DataOutputStream outToClient = new DataOutputStream(connectionSocketgetOutputStream())

clientSentence = inFromClientreadLine()

capitalizedSentence = clientSentencetoUpperCase() + n

outToClientwriteBytes(capitalizedSentence)

connectionSocketclose()

Read in linefrom socket

Create outputstream attached

to socket

Write out lineto socket

End of while looploop back and wait foranother client connection

18-26

Recap

TCP

diams Throughput

diams Fairness

diams Delay modeling

TCP socket programming

18-27

Next time

NAT

Application layer

diams Intro

diams Web HTTP

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
Page 24: 18-1 Last time □ Fast retransmit ♦ 3 duplicate ACKs □ Flow control ♦ Receiver windows □ Connection management ♦ SYN/SYNACK/ACK, FIN/ACK, TCP states □ Congestion

18-24

Example Java server (TCP)

import javaio import javanet

class TCPServer

public static void main(String argv[]) throws Exception String clientSentence String capitalizedSentence

ServerSocket welcomeSocket = new ServerSocket(6789) while(true) Socket connectionSocket = welcomeSocketaccept()

BufferedReader inFromClient = new BufferedReader(new InputStreamReader(connectionSocketgetInputStream()))

Createwelcoming socket

at port 6789

Wait on welcomingsocket for contact

by client

Create inputstream attached

to socket

18-25

Example Java server (TCP) cont

DataOutputStream outToClient = new DataOutputStream(connectionSocketgetOutputStream())

clientSentence = inFromClientreadLine()

capitalizedSentence = clientSentencetoUpperCase() + n

outToClientwriteBytes(capitalizedSentence)

connectionSocketclose()

Read in linefrom socket

Create outputstream attached

to socket

Write out lineto socket

End of while looploop back and wait foranother client connection

18-26

Recap

TCP

diams Throughput

diams Fairness

diams Delay modeling

TCP socket programming

18-27

Next time

NAT

Application layer

diams Intro

diams Web HTTP

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
Page 25: 18-1 Last time □ Fast retransmit ♦ 3 duplicate ACKs □ Flow control ♦ Receiver windows □ Connection management ♦ SYN/SYNACK/ACK, FIN/ACK, TCP states □ Congestion

18-25

Example Java server (TCP) cont

DataOutputStream outToClient = new DataOutputStream(connectionSocketgetOutputStream())

clientSentence = inFromClientreadLine()

capitalizedSentence = clientSentencetoUpperCase() + n

outToClientwriteBytes(capitalizedSentence)

connectionSocketclose()

Read in linefrom socket

Create outputstream attached

to socket

Write out lineto socket

End of while looploop back and wait foranother client connection

18-26

Recap

TCP

diams Throughput

diams Fairness

diams Delay modeling

TCP socket programming

18-27

Next time

NAT

Application layer

diams Intro

diams Web HTTP

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
Page 26: 18-1 Last time □ Fast retransmit ♦ 3 duplicate ACKs □ Flow control ♦ Receiver windows □ Connection management ♦ SYN/SYNACK/ACK, FIN/ACK, TCP states □ Congestion

18-26

Recap

TCP

diams Throughput

diams Fairness

diams Delay modeling

TCP socket programming

18-27

Next time

NAT

Application layer

diams Intro

diams Web HTTP

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27
Page 27: 18-1 Last time □ Fast retransmit ♦ 3 duplicate ACKs □ Flow control ♦ Receiver windows □ Connection management ♦ SYN/SYNACK/ACK, FIN/ACK, TCP states □ Congestion

18-27

Next time

NAT

Application layer

diams Intro

diams Web HTTP

  • Slide 1
  • Slide 2
  • Slide 3
  • Slide 4
  • Slide 5
  • Slide 6
  • Slide 7
  • Slide 8
  • Slide 9
  • Slide 10
  • Slide 11
  • Slide 12
  • Slide 13
  • Slide 14
  • Slide 15
  • Slide 16
  • Slide 17
  • Slide 18
  • Slide 19
  • Slide 20
  • Slide 21
  • Slide 22
  • Slide 23
  • Slide 24
  • Slide 25
  • Slide 26
  • Slide 27