SlideShare a Scribd company logo
1 of 24
Download to read offline
TCP
Transmission Control Protocol
Simple Demultiplexor (UDP)
  Unreliable and unordered datagram service
  Adds multiplexing
  No flow control
  Endpoints identified by ports
   servers have well-known ports
   see /etc/services on Unix       0

                                       SrcPort
                                                 16

                                                         DstPort
                                                                   31




  Header format                        Length           Checksum

                                                 Data




  Optional checksum
   psuedo header + UDP header + data
TCP Overview
Connection-                                     Full duplex
oriented                                        Flow control: keep
Byte-stream                                     sender from
 app writes bytes                               overrunning receiver
 TCP sends                                      Congestion control:
 segments                                       keep sender from
 app reads bytes                                overrunning network
         Application process                       Application process


                           Write                                  Read
                           bytes                                  bytes


                TCP                                        TCP
             Send buffer                              Receive buffer



                       Segment     Segment ■ ■ ■ Segment

                               Transmit segments
TCP Header
         0         4         10            16                      31
                       SrcPort                        DstPort

                                  SequenceNum

                                 Acknowledgment

          HdrLen         0         Flags        AdvertisedWindow

                   Checksum                           UrgPtr

                                 Options (variable)

                                        Data




• Flags: SYN, FIN, RESET, PUSH, URG, ACK
• Checksum: IP pseudo header + TCP header + data
TCP Overview

 When a client requests a connection, it
 sends a “SYN” segment (a special TCP
 segment) to the server port.
 SYN stands for synchronize. The SYN
 message includes the client’s ISN.
 ISN is Initial Sequence Number.
TCP Overview (Contd.)
Every TCP segment includes a Sequence
Number that refers to the first byte of data
included in the segment.
Every TCP segment includes
Acknowledgement Number that indicates
the byte number of the next data that is
expected to be received.
  All bytes up through this number have already
  been received.
TCP Overview (Contd.)

 MSS: Maximum segment size (A TCP
 option)

 Window: Every ACK includes a Window
 field that tells the sender how many bytes
 it can send before the receiver will have to
 toss it away (due to fixed buffer size).
Three-Way Handshake
TCP Connection Establishment
Step 1: Client Starts
  A client starts by sending a SYN segment
  with the following information:
    Client’s ISN (generated pseudo-randomly)
    Maximum Receive Window for client.
    Optionally (but usually) MSS (largest
    datagram accepted).
    No payload! (Only TCP headers)
TCP Connection Establishment
Step 2: Sever Response
  When a waiting server sees a new
  connection request, the server sends
  back a SYN segment with:
    Server’s ISN (generated pseudo-randomly)
    Request Number is Client ISN+1
    Maximum Receive Window for server.
    Optionally (but usually) MSS
    No payload! (Only TCP headers)
TCP Connection Establishment
Step 3:
 When the Server’s SYN is received, the
 client sends back an ACK with:
   Request Number is Server’s ISN+1
TCP Data Transfer

 Once the connection is established, data
 can be sent.
 Each data segment includes a sequence
 number identifying the first byte in the
 segment.
 Each segment (data or empty) includes an
 acknowledgement Number indicating
 what data has been received.
Buffering

 Keep in mind that TCP is part of the
 Operating System. It takes care of all
 these details.
 The TCP layer doesn’t know when the
 application will ask for any received data.
 TCP buffers incoming data so it’s ready
 when we ask for it.
TCP Buffers

 Both the client and server allocate buffers
 to hold incoming and outgoing data
   The TCP layer does this.
 Both the client and server announce how
 much buffer space remains (the Window
 field in a TCP segment).
Send Buffers

 The application gives the TCP layer some data
 to send.
 The data is put in a send buffer, where it stays
 until the data is ACK’d.
   it has to stay, as it might need to be sent again!
 The TCP layer won’t accept data from the
 application unless (or until) there is buffer space.
ACKs

A receiver doesn’t have to ACK every
segment (it can ACK many segments with
a single ACK segment).
Each ACK can also contain outgoing data
(piggybacking).
If a sender doesn’t get an ACK after some
time limit (MSL) it resends the data.
TCP Segment Order

 Most TCP implementations will accept out-of-
 order segments (if there is room in the buffer).
 Once the missing segments arrive, a single ACK
 can be sent for the whole thing.
 Remember: IP delivers TCP segments, and IP in
 not reliable - IP datagrams can be lost or arrive
 out of order.
TCP Connection Termination

 The TCP layer can send a RST segment
 that terminates a connection if something
 is wrong.
 Usually the application tells TCP to
 terminate the connection politely with a
 FIN segment.
FIN
 Either end of the connection can initiate
 termination.
 A FIN is sent, which means the application
 is done sending data.
 The FIN is ACK’d.
 The other end must now send a FIN.
 That FIN must be ACK’d.
App1             App2

         FIN
         FIN
        SN=X
        SN=X


       ACK=X+1
       ACK=X+1



         ...
         FIN
         FIN
        SN=Y
        SN=Y


       ACK=Y+1
       ACK=Y+1
State Transition Diagram
                                            Client                                                                     Server
                                               CLOSED                                                                             CLOSED

                                                                              Active open /SYN                                                                   Active open /SYN
                                                                                                                   Passive open        Close
                             Passive open           Close
                                                                                                                                                        Close
                                                                     Close
                                                                                                                                  LISTEN
                                               LISTEN

                                                                                                           SYN/SYN + ACK              Send/SYN
             SYN/SYN + ACK              Send /SYN                                                                       SYN/SYN + ACK
                                                                                              SYN_RCVD                                                          SYN_SENT
                          SYN/SYN + ACK
SYN_RCVD                                                                     SYN_SENT                                  ACK                  SYN + ACK/ACK

                                       ACK               SYN + ACK/ACK
                                                                                                    Close/FIN                   ESTABLISHED

      Close/FIN                              ESTABLISHED
                                                                                                                  Close/FIN                   FIN/ACK
                                                                                              FIN_WAIT_1                                                        CLOSE_WAIT
                            Close/FIN                      FIN/ACK                                           AC FIN/ACK
                                                                                                    ACK        K                                                     Close/FIN
FIN_WAIT_1                                                                                                       +
                                                                             CLOSE_WAIT                            FI
                                                                                                                      N/
               AC           FIN/ACK                                                           FIN_WAIT_2                 AC      CLOSING                         LAST_ACK
      ACK           K                                                             Close/FIN                                 K
                        +
                            FI                                                                                                       ACK Timeout after two           ACK
                                 N                                                                                                        segment lifetimes
FIN_WAIT_2                        /A          CLOSING                         LAST_ACK                     FIN/ACK
                                       C                                                                                        TIME_WAIT                        CLOSED
                                        K
                                                  ACK Timeout after two           ACK
                                                       segment lifetimes
             FIN/ACK
                                             TIME_WAIT                        CLOSED
TCP TIME_WAIT
 Once a TCP connection has been
 terminated (the last ACK sent) there is
 some unfinished business:
   What if the ACK is lost? The last FIN will
   be resent and it must be ACK’d.
   What if there are lost or duplicated
   segments that finally reach the destination
   after a long delay?
 TCP hangs out for a while (2 * Max.
 Segment Life) to handle these
 situations.
Checking TCP states with netstat
$ netstat -a -n

Active Connections

 Proto   Local Address         Foreign Address        State
 TCP     0.0.0.0:7             0.0.0.0:0              LISTENING
 TCP     0.0.0.0:9             0.0.0.0:0              LISTENING
 TCP     0.0.0.0:13            0.0.0.0:0              LISTENING
 TCP     0.0.0.0:17            0.0.0.0:0              LISTENING
 TCP     0.0.0.0:19            0.0.0.0:0              LISTENING
 TCP     0.0.0.0:21            0.0.0.0:0              LISTENING
 TCP     0.0.0.0:23            0.0.0.0:0              LISTENING
 TCP     0.0.0.0:25            0.0.0.0:0              LISTENING
 TCP     0.0.0.0:80            0.0.0.0:0              LISTENING
 TCP     0.0.0.0:135           0.0.0.0:0              LISTENING
 TCP     0.0.0.0:443           0.0.0.0:0              LISTENING
 TCP     0.0.0.0:445           0.0.0.0:0              LISTENING
 TCP     127.0.0.1:1030        127.0.0.1:7161         ESTABLISHED
 TCP     127.0.0.1:1051        0.0.0.0:0              LISTENING
 TCP     127.0.0.1:7161        0.0.0.0:0              LISTENING
 TCP     127.0.0.1:7161        127.0.0.1:1030         ESTABLISHED
 TCP     141.218.143.76:139    0.0.0.0:0              LISTENING
 TCP     141.218.143.76:1836   141.218.143.43:445     ESTABLISHED
 TCP     141.218.143.76:2003   66.250.84.31:80        ESTABLISHED
 TCP     141.218.143.76:2136   141.218.143.215:22     ESTABLISHED
 TCP     141.218.143.76:3355   216.155.193.166:5050   ESTABLISHED
 TCP     141.218.143.76:3844   141.218.143.10:143     ESTABLISHED
 TCP     141.218.143.76:4635   141.218.143.46:80      ESTABLISHED
 TCP     141.218.143.76:4683   141.218.143.10:143     ESTABLISHED
References
 Cisco Networking Academy Program (CCNA), Cisco Press.

 CSCI-5273 : Computer Networks, Dirk Grunwald, University of Colorado-Boulder

 CSCI-4220: Network Programming, Dave Hollinger, Rensselaer Polytechnic Institute.

 TCP/IP Illustrated, Volume 1, Stevens.

 Java Network Programming and Distributed Computing, Reilly & Reilly.

 Computer Networks: A Systems Approach, Peterson & Davie.

 http://www.firewall.cx

 http://www.javasoft.com

More Related Content

What's hot

What's hot (20)

Transmission Control Protocol
Transmission Control ProtocolTransmission Control Protocol
Transmission Control Protocol
 
How STP and RSTP Works
How STP and RSTP WorksHow STP and RSTP Works
How STP and RSTP Works
 
Go Back N Arq1
Go  Back N Arq1Go  Back N Arq1
Go Back N Arq1
 
New framing-protocols
New framing-protocolsNew framing-protocols
New framing-protocols
 
Advance Repeat reQuest (ARQ)
Advance Repeat reQuest (ARQ)Advance Repeat reQuest (ARQ)
Advance Repeat reQuest (ARQ)
 
Sliding window protocol
Sliding window protocolSliding window protocol
Sliding window protocol
 
Transport protocols
Transport protocolsTransport protocols
Transport protocols
 
Stop And Wait
Stop And WaitStop And Wait
Stop And Wait
 
Aloha4thcsea 160719193815
Aloha4thcsea 160719193815Aloha4thcsea 160719193815
Aloha4thcsea 160719193815
 
Ch 11
Ch 11Ch 11
Ch 11
 
Introduction to TCP
Introduction to TCPIntroduction to TCP
Introduction to TCP
 
VLAN Datapath Walkthrough
VLAN Datapath WalkthroughVLAN Datapath Walkthrough
VLAN Datapath Walkthrough
 
Casing tubing pressure and tank level to abb
Casing tubing pressure and tank level to abbCasing tubing pressure and tank level to abb
Casing tubing pressure and tank level to abb
 
Stop And Wait ARQ
Stop And Wait ARQStop And Wait ARQ
Stop And Wait ARQ
 
Lm2907 Tacometro
Lm2907 TacometroLm2907 Tacometro
Lm2907 Tacometro
 
Synchronization
SynchronizationSynchronization
Synchronization
 
Data Link Control
Data Link ControlData Link Control
Data Link Control
 
Chapter 11
Chapter 11Chapter 11
Chapter 11
 
GO BACK N PROTOCOL
GO BACK N PROTOCOLGO BACK N PROTOCOL
GO BACK N PROTOCOL
 
Module15: Sliding Windows Protocol and Error Control
Module15: Sliding Windows Protocol and Error Control Module15: Sliding Windows Protocol and Error Control
Module15: Sliding Windows Protocol and Error Control
 

Viewers also liked

2015 Live the Lifestyle of your Dreams
2015 Live the Lifestyle of your Dreams2015 Live the Lifestyle of your Dreams
2015 Live the Lifestyle of your DreamsCindy McAsey
 
Avoiding Work at Home Scams
Avoiding Work at Home ScamsAvoiding Work at Home Scams
Avoiding Work at Home Scamsgraspitmarketing
 
Intervento dell'ASL del VCO Convegno Acqua Premia
Intervento dell'ASL del VCO Convegno Acqua PremiaIntervento dell'ASL del VCO Convegno Acqua Premia
Intervento dell'ASL del VCO Convegno Acqua PremiaMassimo Falsaci
 
The process of the making of my music magazine
The process of the making of my music magazineThe process of the making of my music magazine
The process of the making of my music magazineozgealtinok
 
#weightloss 2014 vs Old School #Dieting
#weightloss 2014 vs Old School #Dieting#weightloss 2014 vs Old School #Dieting
#weightloss 2014 vs Old School #DietingCindy McAsey
 
6 в класс
6 в класс6 в класс
6 в классklepa.ru
 
Be Inspired to Dream & Create a Miracle
Be Inspired to Dream & Create a MiracleBe Inspired to Dream & Create a Miracle
Be Inspired to Dream & Create a MiracleCindy McAsey
 
2016 Monitor Awards Gold Winners: Life Insurance
2016 Monitor Awards Gold Winners: Life Insurance2016 Monitor Awards Gold Winners: Life Insurance
2016 Monitor Awards Gold Winners: Life InsuranceCorporate Insight
 
Andy Wells Publicatons May 2016
Andy Wells Publicatons  May 2016Andy Wells Publicatons  May 2016
Andy Wells Publicatons May 2016Andy Wells
 
Klepa альманах
Klepa альманахKlepa альманах
Klepa альманахklepa.ru
 
Новости недвижимости майами апрель 2016
Новости недвижимости майами апрель 2016 Новости недвижимости майами апрель 2016
Новости недвижимости майами апрель 2016 The Reznik Group
 
Back to school night 2016 slideshare
Back to school night 2016 slideshareBack to school night 2016 slideshare
Back to school night 2016 slideshareccantlie
 
Benefits of Mobile Apps: How it is Making Our Life Easier
Benefits of Mobile Apps: How it is Making Our Life EasierBenefits of Mobile Apps: How it is Making Our Life Easier
Benefits of Mobile Apps: How it is Making Our Life EasierArth I-Soft
 

Viewers also liked (19)

2015 Live the Lifestyle of your Dreams
2015 Live the Lifestyle of your Dreams2015 Live the Lifestyle of your Dreams
2015 Live the Lifestyle of your Dreams
 
10 back
10 back10 back
10 back
 
Avoiding Work at Home Scams
Avoiding Work at Home ScamsAvoiding Work at Home Scams
Avoiding Work at Home Scams
 
Intervento dell'ASL del VCO Convegno Acqua Premia
Intervento dell'ASL del VCO Convegno Acqua PremiaIntervento dell'ASL del VCO Convegno Acqua Premia
Intervento dell'ASL del VCO Convegno Acqua Premia
 
The process of the making of my music magazine
The process of the making of my music magazineThe process of the making of my music magazine
The process of the making of my music magazine
 
#weightloss 2014 vs Old School #Dieting
#weightloss 2014 vs Old School #Dieting#weightloss 2014 vs Old School #Dieting
#weightloss 2014 vs Old School #Dieting
 
6 в класс
6 в класс6 в класс
6 в класс
 
Nokia 2600C specification
Nokia 2600C specificationNokia 2600C specification
Nokia 2600C specification
 
Search for Wisdom activity
Search for Wisdom activitySearch for Wisdom activity
Search for Wisdom activity
 
La realtà aumentata
La realtà aumentataLa realtà aumentata
La realtà aumentata
 
Be Inspired to Dream & Create a Miracle
Be Inspired to Dream & Create a MiracleBe Inspired to Dream & Create a Miracle
Be Inspired to Dream & Create a Miracle
 
MetastudioDRM
MetastudioDRMMetastudioDRM
MetastudioDRM
 
2016 Monitor Awards Gold Winners: Life Insurance
2016 Monitor Awards Gold Winners: Life Insurance2016 Monitor Awards Gold Winners: Life Insurance
2016 Monitor Awards Gold Winners: Life Insurance
 
Andy Wells Publicatons May 2016
Andy Wells Publicatons  May 2016Andy Wells Publicatons  May 2016
Andy Wells Publicatons May 2016
 
Klepa альманах
Klepa альманахKlepa альманах
Klepa альманах
 
Новости недвижимости майами апрель 2016
Новости недвижимости майами апрель 2016 Новости недвижимости майами апрель 2016
Новости недвижимости майами апрель 2016
 
Back to school night 2016 slideshare
Back to school night 2016 slideshareBack to school night 2016 slideshare
Back to school night 2016 slideshare
 
DOKBAT 2015
DOKBAT 2015DOKBAT 2015
DOKBAT 2015
 
Benefits of Mobile Apps: How it is Making Our Life Easier
Benefits of Mobile Apps: How it is Making Our Life EasierBenefits of Mobile Apps: How it is Making Our Life Easier
Benefits of Mobile Apps: How it is Making Our Life Easier
 

Similar to Lecture9

Similar to Lecture9 (20)

Unit III IPV6 UDP
Unit III IPV6 UDPUnit III IPV6 UDP
Unit III IPV6 UDP
 
08 module interconnecting cisco router
08 module interconnecting cisco router08 module interconnecting cisco router
08 module interconnecting cisco router
 
Transport Layer in Computer Networks (TCP / UDP / SCTP)
Transport Layer in Computer Networks (TCP / UDP / SCTP)Transport Layer in Computer Networks (TCP / UDP / SCTP)
Transport Layer in Computer Networks (TCP / UDP / SCTP)
 
13_TCP_Attack.pptx
13_TCP_Attack.pptx13_TCP_Attack.pptx
13_TCP_Attack.pptx
 
Socket网络编程
Socket网络编程Socket网络编程
Socket网络编程
 
Course on TCP Dynamic Performance
Course on TCP Dynamic PerformanceCourse on TCP Dynamic Performance
Course on TCP Dynamic Performance
 
TCP - Transmission Control Protocol
TCP - Transmission Control ProtocolTCP - Transmission Control Protocol
TCP - Transmission Control Protocol
 
Chapter 3 - Transport Layer
Chapter 3 - Transport LayerChapter 3 - Transport Layer
Chapter 3 - Transport Layer
 
TCP/IP
TCP/IPTCP/IP
TCP/IP
 
Np unit1
Np unit1Np unit1
Np unit1
 
Np unit iii
Np unit iiiNp unit iii
Np unit iii
 
Mobile Transpot Layer
Mobile Transpot LayerMobile Transpot Layer
Mobile Transpot Layer
 
7 tcp-congestion
7 tcp-congestion7 tcp-congestion
7 tcp-congestion
 
Plan 9カーネルにおけるTCP/IP実装(未完)
Plan 9カーネルにおけるTCP/IP実装(未完)Plan 9カーネルにおけるTCP/IP実装(未完)
Plan 9カーネルにおけるTCP/IP実装(未完)
 
Lecture 5
Lecture 5Lecture 5
Lecture 5
 
Tcp congestion avoidance
Tcp congestion avoidanceTcp congestion avoidance
Tcp congestion avoidance
 
Computer network (13)
Computer network (13)Computer network (13)
Computer network (13)
 
Transport Layer Description By Varun Tiwari
Transport Layer Description By Varun TiwariTransport Layer Description By Varun Tiwari
Transport Layer Description By Varun Tiwari
 
chapter 3.2 TCP.pptx
chapter 3.2 TCP.pptxchapter 3.2 TCP.pptx
chapter 3.2 TCP.pptx
 
Transport layer
Transport layerTransport layer
Transport layer
 

More from vantinhkhuc (20)

Url programming
Url programmingUrl programming
Url programming
 
Servlets intro
Servlets introServlets intro
Servlets intro
 
Servlet sessions
Servlet sessionsServlet sessions
Servlet sessions
 
Security overview
Security overviewSecurity overview
Security overview
 
Rmi
RmiRmi
Rmi
 
Md5
Md5Md5
Md5
 
Lecture17
Lecture17Lecture17
Lecture17
 
Lecture11 b
Lecture11 bLecture11 b
Lecture11 b
 
Lecture10
Lecture10Lecture10
Lecture10
 
Lecture6
Lecture6Lecture6
Lecture6
 
Jsse
JsseJsse
Jsse
 
Jsf intro
Jsf introJsf intro
Jsf intro
 
Jsp examples
Jsp examplesJsp examples
Jsp examples
 
Jpa
JpaJpa
Jpa
 
Ejb examples
Ejb examplesEjb examples
Ejb examples
 
Corba
CorbaCorba
Corba
 
Ajax
AjaxAjax
Ajax
 
Ejb intro
Ejb introEjb intro
Ejb intro
 
Chc6b0c6a1ng 12
Chc6b0c6a1ng 12Chc6b0c6a1ng 12
Chc6b0c6a1ng 12
 
Ch06
Ch06Ch06
Ch06
 

Lecture9

  • 2. Simple Demultiplexor (UDP) Unreliable and unordered datagram service Adds multiplexing No flow control Endpoints identified by ports servers have well-known ports see /etc/services on Unix 0 SrcPort 16 DstPort 31 Header format Length Checksum Data Optional checksum psuedo header + UDP header + data
  • 3. TCP Overview Connection- Full duplex oriented Flow control: keep Byte-stream sender from app writes bytes overrunning receiver TCP sends Congestion control: segments keep sender from app reads bytes overrunning network Application process Application process Write Read bytes bytes TCP TCP Send buffer Receive buffer Segment Segment ■ ■ ■ Segment Transmit segments
  • 4. TCP Header 0 4 10 16 31 SrcPort DstPort SequenceNum Acknowledgment HdrLen 0 Flags AdvertisedWindow Checksum UrgPtr Options (variable) Data • Flags: SYN, FIN, RESET, PUSH, URG, ACK • Checksum: IP pseudo header + TCP header + data
  • 5. TCP Overview When a client requests a connection, it sends a “SYN” segment (a special TCP segment) to the server port. SYN stands for synchronize. The SYN message includes the client’s ISN. ISN is Initial Sequence Number.
  • 6. TCP Overview (Contd.) Every TCP segment includes a Sequence Number that refers to the first byte of data included in the segment. Every TCP segment includes Acknowledgement Number that indicates the byte number of the next data that is expected to be received. All bytes up through this number have already been received.
  • 7. TCP Overview (Contd.) MSS: Maximum segment size (A TCP option) Window: Every ACK includes a Window field that tells the sender how many bytes it can send before the receiver will have to toss it away (due to fixed buffer size).
  • 9. TCP Connection Establishment Step 1: Client Starts A client starts by sending a SYN segment with the following information: Client’s ISN (generated pseudo-randomly) Maximum Receive Window for client. Optionally (but usually) MSS (largest datagram accepted). No payload! (Only TCP headers)
  • 10. TCP Connection Establishment Step 2: Sever Response When a waiting server sees a new connection request, the server sends back a SYN segment with: Server’s ISN (generated pseudo-randomly) Request Number is Client ISN+1 Maximum Receive Window for server. Optionally (but usually) MSS No payload! (Only TCP headers)
  • 11. TCP Connection Establishment Step 3: When the Server’s SYN is received, the client sends back an ACK with: Request Number is Server’s ISN+1
  • 12. TCP Data Transfer Once the connection is established, data can be sent. Each data segment includes a sequence number identifying the first byte in the segment. Each segment (data or empty) includes an acknowledgement Number indicating what data has been received.
  • 13. Buffering Keep in mind that TCP is part of the Operating System. It takes care of all these details. The TCP layer doesn’t know when the application will ask for any received data. TCP buffers incoming data so it’s ready when we ask for it.
  • 14. TCP Buffers Both the client and server allocate buffers to hold incoming and outgoing data The TCP layer does this. Both the client and server announce how much buffer space remains (the Window field in a TCP segment).
  • 15. Send Buffers The application gives the TCP layer some data to send. The data is put in a send buffer, where it stays until the data is ACK’d. it has to stay, as it might need to be sent again! The TCP layer won’t accept data from the application unless (or until) there is buffer space.
  • 16. ACKs A receiver doesn’t have to ACK every segment (it can ACK many segments with a single ACK segment). Each ACK can also contain outgoing data (piggybacking). If a sender doesn’t get an ACK after some time limit (MSL) it resends the data.
  • 17. TCP Segment Order Most TCP implementations will accept out-of- order segments (if there is room in the buffer). Once the missing segments arrive, a single ACK can be sent for the whole thing. Remember: IP delivers TCP segments, and IP in not reliable - IP datagrams can be lost or arrive out of order.
  • 18. TCP Connection Termination The TCP layer can send a RST segment that terminates a connection if something is wrong. Usually the application tells TCP to terminate the connection politely with a FIN segment.
  • 19. FIN Either end of the connection can initiate termination. A FIN is sent, which means the application is done sending data. The FIN is ACK’d. The other end must now send a FIN. That FIN must be ACK’d.
  • 20. App1 App2 FIN FIN SN=X SN=X ACK=X+1 ACK=X+1 ... FIN FIN SN=Y SN=Y ACK=Y+1 ACK=Y+1
  • 21. State Transition Diagram Client Server CLOSED CLOSED Active open /SYN Active open /SYN Passive open Close Passive open Close Close Close LISTEN LISTEN SYN/SYN + ACK Send/SYN SYN/SYN + ACK Send /SYN SYN/SYN + ACK SYN_RCVD SYN_SENT SYN/SYN + ACK SYN_RCVD SYN_SENT ACK SYN + ACK/ACK ACK SYN + ACK/ACK Close/FIN ESTABLISHED Close/FIN ESTABLISHED Close/FIN FIN/ACK FIN_WAIT_1 CLOSE_WAIT Close/FIN FIN/ACK AC FIN/ACK ACK K Close/FIN FIN_WAIT_1 + CLOSE_WAIT FI N/ AC FIN/ACK FIN_WAIT_2 AC CLOSING LAST_ACK ACK K Close/FIN K + FI ACK Timeout after two ACK N segment lifetimes FIN_WAIT_2 /A CLOSING LAST_ACK FIN/ACK C TIME_WAIT CLOSED K ACK Timeout after two ACK segment lifetimes FIN/ACK TIME_WAIT CLOSED
  • 22. TCP TIME_WAIT Once a TCP connection has been terminated (the last ACK sent) there is some unfinished business: What if the ACK is lost? The last FIN will be resent and it must be ACK’d. What if there are lost or duplicated segments that finally reach the destination after a long delay? TCP hangs out for a while (2 * Max. Segment Life) to handle these situations.
  • 23. Checking TCP states with netstat $ netstat -a -n Active Connections Proto Local Address Foreign Address State TCP 0.0.0.0:7 0.0.0.0:0 LISTENING TCP 0.0.0.0:9 0.0.0.0:0 LISTENING TCP 0.0.0.0:13 0.0.0.0:0 LISTENING TCP 0.0.0.0:17 0.0.0.0:0 LISTENING TCP 0.0.0.0:19 0.0.0.0:0 LISTENING TCP 0.0.0.0:21 0.0.0.0:0 LISTENING TCP 0.0.0.0:23 0.0.0.0:0 LISTENING TCP 0.0.0.0:25 0.0.0.0:0 LISTENING TCP 0.0.0.0:80 0.0.0.0:0 LISTENING TCP 0.0.0.0:135 0.0.0.0:0 LISTENING TCP 0.0.0.0:443 0.0.0.0:0 LISTENING TCP 0.0.0.0:445 0.0.0.0:0 LISTENING TCP 127.0.0.1:1030 127.0.0.1:7161 ESTABLISHED TCP 127.0.0.1:1051 0.0.0.0:0 LISTENING TCP 127.0.0.1:7161 0.0.0.0:0 LISTENING TCP 127.0.0.1:7161 127.0.0.1:1030 ESTABLISHED TCP 141.218.143.76:139 0.0.0.0:0 LISTENING TCP 141.218.143.76:1836 141.218.143.43:445 ESTABLISHED TCP 141.218.143.76:2003 66.250.84.31:80 ESTABLISHED TCP 141.218.143.76:2136 141.218.143.215:22 ESTABLISHED TCP 141.218.143.76:3355 216.155.193.166:5050 ESTABLISHED TCP 141.218.143.76:3844 141.218.143.10:143 ESTABLISHED TCP 141.218.143.76:4635 141.218.143.46:80 ESTABLISHED TCP 141.218.143.76:4683 141.218.143.10:143 ESTABLISHED
  • 24. References Cisco Networking Academy Program (CCNA), Cisco Press. CSCI-5273 : Computer Networks, Dirk Grunwald, University of Colorado-Boulder CSCI-4220: Network Programming, Dave Hollinger, Rensselaer Polytechnic Institute. TCP/IP Illustrated, Volume 1, Stevens. Java Network Programming and Distributed Computing, Reilly & Reilly. Computer Networks: A Systems Approach, Peterson & Davie. http://www.firewall.cx http://www.javasoft.com