SlideShare una empresa de Scribd logo
1 de 37
Socket网络编程
大纲
•   TCP/UDP
•   Socket
•   HTTP
•   Unix IO 模型
TCP-UDP 对比
UDP
• User Datagram Protocol
TCP
• Transmission Control Protocol
TCP——连接建立
• Before a client attempts to connect with a server, the server must first
  bind to and listen at a port to open it up for connections: this is called a
  passive open. Once the passive open is established, a client may initiate an
  active open.

    – SYN: The active open is performed by the client sending a SYN to the server.
      The client sets the segment's sequence number to a random value A.
    – SYN-ACK: In response, the server replies with a SYN-ACK. The
      acknowledgment number is set to one more than the received sequence
      number (A + 1), and the sequence number that the server chooses for the
      packet is another random number, B.
    – ACK: Finally, the client sends an ACK back to the server. The sequence number
      is set to the received acknowledgement value i.e. A + 1, and the
      acknowledgement number is set to one more than the received sequence
      number i.e. B + 1.
TCP——连接关闭
• The connection termination phase uses a four-way handshake, with
  each side of the connection terminating independently.
• When an endpoint wishes to stop its half of the connection, it
  transmits a FIN packet, which the other end acknowledges with an
  ACK.
• Therefore, a typical tear-down requires a pair of FIN and ACK
  segments from each TCP endpoint.
• After both FIN/ACK exchanges are concluded, the side which sent
  the first FIN before receiving one waits for a timeout before finally
  closing the connection, during which time the local port is
  unavailable for new connections; this prevents confusion due to
  delayed packets being delivered during subsequent connections.
TCP——连接关闭
TCP——整个过程
TCP——netstat
•   LISTEN
•   (server) represents waiting for a connection request from any remote TCP and port.
•   SYN-SENT
•   (client) represents waiting for a matching connection request after having sent a
    connection request.
•   SYN-RECEIVED
•   (server) represents waiting for a confirming connection request acknowledgment
    after having both received and sent a connection request.
•   ESTABLISHED
•   (both server and client) represents an open connection, data received can be
    delivered to the user. The normal state for the data transfer phase of the
    connection.
TCP——netstat
•   FIN-WAIT-1
•   (both server and client) represents waiting for a connection termination request from the remote TCP, or an
    acknowledgment of the connection termination request previously sent.
•   FIN-WAIT-2
•   (both server and client) represents waiting for a connection termination request from the remote TCP.
•   CLOSE-WAIT
•   (both server and client) represents waiting for a connection termination request from the local user.
•   CLOSING
•   (both server and client) represents waiting for a connection termination request acknowledgment from the
    remote TCP.
•   LAST-ACK
•   (both server and client) represents waiting for an acknowledgment of the connection termination request
    previously sent to the remote TCP (which includes an acknowledgment of its connection termination request).
•   TIME-WAIT
•   (either server or client) represents waiting for enough time to pass to be sure the remote TCP received the
    acknowledgment of its connection termination request.
•   CLOSED
•   (both server and client) represents no connection state at all.
Socket
• A network socket is an endpoint of an inter-process communication
  flow across a computer network. Today, most communication
  between computers is based on the Internet Protocol; therefore
  most network sockets are Internet sockets.
• A socket API is an application programming interface (API), usually
  provided by the operating system, that allows application programs
  to control and use network sockets. Internet socket APIs are usually
  based on the Berkeley sockets standard.
• A socket address is the combination of an IP address and a port
  number, much like one end of a telephone connection is the
  combination of a phone number and a particular extension. Based
  on this address, internet sockets deliver incoming data packets to
  the appropriate application process or thread.
Socket——基于UDP编程流程
Socket——基于TCP编程流程
Socket——选项
•   SO_DEBUG
•   SO_DONTROUTE
•   SO_KEEPALIVE
•   SO_DONTLINER
•   SO_LINGER
•   SO_RCVBUF
•   SO_SNDBUF
•   SO_REUSERADDR
•   SO_RCVTIMEO
•   SO_SNDTIMEO
•   TCP_NODELAY(Nagle)
HTTP
• Hypertext Transfer Protocol
• HTTP functions as a request-response protocol
  in the client-server computing model.
HTTP——Request
• Request methods
  – HEAD/GET/POST/PUT/DELETE/TRACE/OPTIONS/C
    ONNECT/PATCH
HTTP——GET POST
• GET 参数

• POST 参数
 – application/x-www-form-urlencoded
 – multipart/form-data(non-ASCII data, and binary
   data)
HTTP——POST multipart/form-data
HTTP——Request Header
HTTP——Request Header
HTTP——Request Header
HTTP——Response
• Status codes
  – 1xx Informational/2xx Success/3xx
    Redirection/4xx Client Error/5xx Server Error
HTTP——Response Header
HTTP——Response Header
HTTP——Response Header
HTTP——Response Header
HTTP——Persistent connections
• Persistent connections
  – In HTTP/0.9 and 1.0, the connection is closed after
    a single request/response pair. In HTTP/1.1 a
    keep-alive-mechanism was introduced, where a
    connection could be reused for more than one
    request.
Unix IO 模型
• Unix下共有五种I/O模型

  – 阻塞I/O

  – 非阻塞I/O

  – I/O复用(select和poll)

  – 信号驱动I/O(SIGIO)

  – 异步I/O(Posix.1的aio_系列函数)
Unix IO 模型——阻塞IO
Unix IO 模型——非阻塞IO
Unix IO 模型——IO复用
Unix IO 模型——信号驱动IO
Unix IO 模型——异步IO
Unix IO 模型——对比
Unix IO 模型——异步IO
END

Más contenido relacionado

La actualidad más candente

Surviving The Stump The Chump Interview Questions
Surviving The Stump The Chump Interview QuestionsSurviving The Stump The Chump Interview Questions
Surviving The Stump The Chump Interview QuestionsDuane Bodle
 
Client server examples for tcp abnormal conditions
Client server examples for tcp abnormal conditionsClient server examples for tcp abnormal conditions
Client server examples for tcp abnormal conditionsCEC Landran
 
Network interview questions
Network interview questionsNetwork interview questions
Network interview questionsrajasekar1712
 
Solar windsportrequirements
Solar windsportrequirementsSolar windsportrequirements
Solar windsportrequirementsnasac
 
IP/MAC Address Translation
IP/MAC Address TranslationIP/MAC Address Translation
IP/MAC Address TranslationIsmail Mukiibi
 
Part 4 : reliable transport and sharing resources
Part 4 : reliable transport and sharing resourcesPart 4 : reliable transport and sharing resources
Part 4 : reliable transport and sharing resourcesOlivier Bonaventure
 
Transmission Control Protocol (TCP)
Transmission Control Protocol (TCP)Transmission Control Protocol (TCP)
Transmission Control Protocol (TCP)k33a
 
Traffic Characterization
Traffic CharacterizationTraffic Characterization
Traffic CharacterizationIsmail Mukiibi
 
Initial LTE call Setup Flow
Initial LTE call Setup FlowInitial LTE call Setup Flow
Initial LTE call Setup Flowassinha
 
TELNET and SSH by MUSTAFA SAKHAI
TELNET and SSH by MUSTAFA SAKHAITELNET and SSH by MUSTAFA SAKHAI
TELNET and SSH by MUSTAFA SAKHAIMUSTAFA SAKHAI
 

La actualidad más candente (20)

Surviving The Stump The Chump Interview Questions
Surviving The Stump The Chump Interview QuestionsSurviving The Stump The Chump Interview Questions
Surviving The Stump The Chump Interview Questions
 
Port numbers
Port numbersPort numbers
Port numbers
 
Dhcp Snooping
Dhcp SnoopingDhcp Snooping
Dhcp Snooping
 
CCNA 1 Chapter 7 v5.0 2014
CCNA 1 Chapter 7 v5.0 2014CCNA 1 Chapter 7 v5.0 2014
CCNA 1 Chapter 7 v5.0 2014
 
Client server examples for tcp abnormal conditions
Client server examples for tcp abnormal conditionsClient server examples for tcp abnormal conditions
Client server examples for tcp abnormal conditions
 
6 app-tcp
6 app-tcp6 app-tcp
6 app-tcp
 
Part 7 : HTTP/2, UDP and TCP
Part 7 : HTTP/2, UDP and TCPPart 7 : HTTP/2, UDP and TCP
Part 7 : HTTP/2, UDP and TCP
 
Chap 18 telnet
Chap 18 telnetChap 18 telnet
Chap 18 telnet
 
Network interview questions
Network interview questionsNetwork interview questions
Network interview questions
 
Part 6 : Internet applications
Part 6 : Internet applicationsPart 6 : Internet applications
Part 6 : Internet applications
 
IMS Session Flow
IMS Session FlowIMS Session Flow
IMS Session Flow
 
Solar windsportrequirements
Solar windsportrequirementsSolar windsportrequirements
Solar windsportrequirements
 
Well known protocols port numbers
Well known  protocols port numbersWell known  protocols port numbers
Well known protocols port numbers
 
Part 12 : Local Area Networks
Part 12 : Local Area Networks Part 12 : Local Area Networks
Part 12 : Local Area Networks
 
IP/MAC Address Translation
IP/MAC Address TranslationIP/MAC Address Translation
IP/MAC Address Translation
 
Part 4 : reliable transport and sharing resources
Part 4 : reliable transport and sharing resourcesPart 4 : reliable transport and sharing resources
Part 4 : reliable transport and sharing resources
 
Transmission Control Protocol (TCP)
Transmission Control Protocol (TCP)Transmission Control Protocol (TCP)
Transmission Control Protocol (TCP)
 
Traffic Characterization
Traffic CharacterizationTraffic Characterization
Traffic Characterization
 
Initial LTE call Setup Flow
Initial LTE call Setup FlowInitial LTE call Setup Flow
Initial LTE call Setup Flow
 
TELNET and SSH by MUSTAFA SAKHAI
TELNET and SSH by MUSTAFA SAKHAITELNET and SSH by MUSTAFA SAKHAI
TELNET and SSH by MUSTAFA SAKHAI
 

Destacado

Course on TCP Dynamic Performance
Course on TCP Dynamic PerformanceCourse on TCP Dynamic Performance
Course on TCP Dynamic PerformanceJavier Arauz
 
TCP with delayed ack for wireless networks
TCP with delayed ack for wireless networksTCP with delayed ack for wireless networks
TCP with delayed ack for wireless networksambitlicksolutions
 
Lecture 5
Lecture 5Lecture 5
Lecture 5ntpc08
 
CS4344 09/10 Lecture 10: Transport Protocol for Networked Games
CS4344 09/10 Lecture 10: Transport Protocol for Networked GamesCS4344 09/10 Lecture 10: Transport Protocol for Networked Games
CS4344 09/10 Lecture 10: Transport Protocol for Networked GamesWei Tsang Ooi
 
Flow & Error Control
Flow & Error ControlFlow & Error Control
Flow & Error Controltameemyousaf
 

Destacado (8)

Course on TCP Dynamic Performance
Course on TCP Dynamic PerformanceCourse on TCP Dynamic Performance
Course on TCP Dynamic Performance
 
TCP Model
TCP ModelTCP Model
TCP Model
 
TCP with delayed ack for wireless networks
TCP with delayed ack for wireless networksTCP with delayed ack for wireless networks
TCP with delayed ack for wireless networks
 
Lecture 5
Lecture 5Lecture 5
Lecture 5
 
CS4344 09/10 Lecture 10: Transport Protocol for Networked Games
CS4344 09/10 Lecture 10: Transport Protocol for Networked GamesCS4344 09/10 Lecture 10: Transport Protocol for Networked Games
CS4344 09/10 Lecture 10: Transport Protocol for Networked Games
 
Flow & Error Control
Flow & Error ControlFlow & Error Control
Flow & Error Control
 
4 transport-sharing
4 transport-sharing4 transport-sharing
4 transport-sharing
 
2 reliability-network
2 reliability-network2 reliability-network
2 reliability-network
 

Similar a Socket网络编程概述

Similar a Socket网络编程概述 (20)

TCP/IP
TCP/IPTCP/IP
TCP/IP
 
tcp-ippresentation-150614172243-lva1-app6892.pptx
tcp-ippresentation-150614172243-lva1-app6892.pptxtcp-ippresentation-150614172243-lva1-app6892.pptx
tcp-ippresentation-150614172243-lva1-app6892.pptx
 
CCNA (R & S) Module 01 - Introduction to Networks - Chapter 9
CCNA (R & S) Module 01 - Introduction to Networks - Chapter 9CCNA (R & S) Module 01 - Introduction to Networks - Chapter 9
CCNA (R & S) Module 01 - Introduction to Networks - Chapter 9
 
TCP - IP Presentation
TCP - IP PresentationTCP - IP Presentation
TCP - IP Presentation
 
Tcp ip presentation
Tcp ip presentationTcp ip presentation
Tcp ip presentation
 
Java socket programming
Java socket programmingJava socket programming
Java socket programming
 
lecturer3.pptx
lecturer3.pptxlecturer3.pptx
lecturer3.pptx
 
Unit-4 (1).pptx
Unit-4 (1).pptxUnit-4 (1).pptx
Unit-4 (1).pptx
 
TCP/IP(networking)
TCP/IP(networking)TCP/IP(networking)
TCP/IP(networking)
 
Np unit iv ii
Np unit iv iiNp unit iv ii
Np unit iv ii
 
08 coms 525 tcpip - tcp 1
08   coms 525 tcpip - tcp 108   coms 525 tcpip - tcp 1
08 coms 525 tcpip - tcp 1
 
TCP /IP
TCP /IPTCP /IP
TCP /IP
 
Tcp
TcpTcp
Tcp
 
Lecture set 7
Lecture set 7Lecture set 7
Lecture set 7
 
Byte Ordering - Unit 2.pptx
Byte Ordering - Unit 2.pptxByte Ordering - Unit 2.pptx
Byte Ordering - Unit 2.pptx
 
Java_Socket_Programming (2).ppt
Java_Socket_Programming (2).pptJava_Socket_Programming (2).ppt
Java_Socket_Programming (2).ppt
 
Socket programming using C
Socket programming using CSocket programming using C
Socket programming using C
 
Network performance overview
Network  performance overviewNetwork  performance overview
Network performance overview
 
Flow control
Flow controlFlow control
Flow control
 
Transport layer
Transport layerTransport layer
Transport layer
 

Último

TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 

Último (20)

TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 

Socket网络编程概述

  • 2. 大纲 • TCP/UDP • Socket • HTTP • Unix IO 模型
  • 6. TCP——连接建立 • Before a client attempts to connect with a server, the server must first bind to and listen at a port to open it up for connections: this is called a passive open. Once the passive open is established, a client may initiate an active open. – SYN: The active open is performed by the client sending a SYN to the server. The client sets the segment's sequence number to a random value A. – SYN-ACK: In response, the server replies with a SYN-ACK. The acknowledgment number is set to one more than the received sequence number (A + 1), and the sequence number that the server chooses for the packet is another random number, B. – ACK: Finally, the client sends an ACK back to the server. The sequence number is set to the received acknowledgement value i.e. A + 1, and the acknowledgement number is set to one more than the received sequence number i.e. B + 1.
  • 7. TCP——连接关闭 • The connection termination phase uses a four-way handshake, with each side of the connection terminating independently. • When an endpoint wishes to stop its half of the connection, it transmits a FIN packet, which the other end acknowledges with an ACK. • Therefore, a typical tear-down requires a pair of FIN and ACK segments from each TCP endpoint. • After both FIN/ACK exchanges are concluded, the side which sent the first FIN before receiving one waits for a timeout before finally closing the connection, during which time the local port is unavailable for new connections; this prevents confusion due to delayed packets being delivered during subsequent connections.
  • 10. TCP——netstat • LISTEN • (server) represents waiting for a connection request from any remote TCP and port. • SYN-SENT • (client) represents waiting for a matching connection request after having sent a connection request. • SYN-RECEIVED • (server) represents waiting for a confirming connection request acknowledgment after having both received and sent a connection request. • ESTABLISHED • (both server and client) represents an open connection, data received can be delivered to the user. The normal state for the data transfer phase of the connection.
  • 11. TCP——netstat • FIN-WAIT-1 • (both server and client) represents waiting for a connection termination request from the remote TCP, or an acknowledgment of the connection termination request previously sent. • FIN-WAIT-2 • (both server and client) represents waiting for a connection termination request from the remote TCP. • CLOSE-WAIT • (both server and client) represents waiting for a connection termination request from the local user. • CLOSING • (both server and client) represents waiting for a connection termination request acknowledgment from the remote TCP. • LAST-ACK • (both server and client) represents waiting for an acknowledgment of the connection termination request previously sent to the remote TCP (which includes an acknowledgment of its connection termination request). • TIME-WAIT • (either server or client) represents waiting for enough time to pass to be sure the remote TCP received the acknowledgment of its connection termination request. • CLOSED • (both server and client) represents no connection state at all.
  • 12. Socket • A network socket is an endpoint of an inter-process communication flow across a computer network. Today, most communication between computers is based on the Internet Protocol; therefore most network sockets are Internet sockets. • A socket API is an application programming interface (API), usually provided by the operating system, that allows application programs to control and use network sockets. Internet socket APIs are usually based on the Berkeley sockets standard. • A socket address is the combination of an IP address and a port number, much like one end of a telephone connection is the combination of a phone number and a particular extension. Based on this address, internet sockets deliver incoming data packets to the appropriate application process or thread.
  • 15. Socket——选项 • SO_DEBUG • SO_DONTROUTE • SO_KEEPALIVE • SO_DONTLINER • SO_LINGER • SO_RCVBUF • SO_SNDBUF • SO_REUSERADDR • SO_RCVTIMEO • SO_SNDTIMEO • TCP_NODELAY(Nagle)
  • 16. HTTP • Hypertext Transfer Protocol • HTTP functions as a request-response protocol in the client-server computing model.
  • 17. HTTP——Request • Request methods – HEAD/GET/POST/PUT/DELETE/TRACE/OPTIONS/C ONNECT/PATCH
  • 18. HTTP——GET POST • GET 参数 • POST 参数 – application/x-www-form-urlencoded – multipart/form-data(non-ASCII data, and binary data)
  • 23. HTTP——Response • Status codes – 1xx Informational/2xx Success/3xx Redirection/4xx Client Error/5xx Server Error
  • 28. HTTP——Persistent connections • Persistent connections – In HTTP/0.9 and 1.0, the connection is closed after a single request/response pair. In HTTP/1.1 a keep-alive-mechanism was introduced, where a connection could be reused for more than one request.
  • 29. Unix IO 模型 • Unix下共有五种I/O模型 – 阻塞I/O – 非阻塞I/O – I/O复用(select和poll) – 信号驱动I/O(SIGIO) – 异步I/O(Posix.1的aio_系列函数)
  • 37. END