Web server-based sockets and TCP protocols

Source: Internet
Author: User

Objective

Based on C/s architecture.

Web Service: Application layer protocol. (HTTP,HTTPS)

Solve a specific type of application, with the application space of some kind of application to be responsible for the completion.

Client: Browser-to-Application layer protocol: Http-->web Server (socket-based communication)

======================================== Split Line =============================================

The communication process between networks relies on socket files (ip/port) for communication, and applications in the application layer want to communicate with other non-native processes in the network through sockets, and the application needs to make system calls to provide the functionality of the kernel space to the application. The application can then reach the target host server through the Transport Layer, network layer, and data link layer of the kernel space.

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M01/79/8B/wKiom1aUbpiBroJqAAIyb24H2KA438.jpg "title=" Network communications. jpg "alt=" wkiom1aubpibrojqaaiyb24h2ka438.jpg "/>

BSD socket (SOCKET): an implementation of IPC that allows communication between processes located on different hosts (or the same host);

Socket API (encapsulates the system calls related to socket communication in the kernel)

According to the Protocol classification of sockets:

SOCK_STREAM:TCP sockets

SOCK_DGRAM:UDP sockets

Sock_raw:raw set by word

Classification according to the address format used by the socket, socket Domain:

Af_inet:address Family,ipv4

Af_inet6:ipv6

Af_unix: An address that is used by socket sockets communication between different processes on the same host Unix_sock



In the process of communication, the server also calls a well-known port from the kernel in advance through a layer of system calls and enters the listening state waiting for the client to establish a connection with it.

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M02/79/8A/wKioL1aUcXuw_4x8AAEUqX9F8g0317.png "title=" Communication mechanism. PNG "alt=" Wkiol1aucxuw_4x8aaeuqx9f8g0317.png "/>

This will involve a three-time handshake between the client and the server and four disconnects when the connection is disconnected.


Three-time handshake:

The ① client sends a request to the server side, which receives the request and responds with the first handshake.

② server-side response requests are sent to the client, which is the second handshake.

The ③ client receives the server-side request and responds to the service side, which is the third handshake.

After three handshake, the client and server have established a connection and can perform multiple communication processes.

(Note: We can assume that the client sends a request to the server and the server sends the request to the client and not on a transmission link, which is, of course, a logical concept and does not mean that there really are two links, so understanding can also help us understand the process of four disconnects.) )

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M00/79/8A/wKioL1aUcdOAz272AAEZj5qq35k688.gif "title=" Three-time handshake. gif "alt=" Wkiol1aucdoaz272aaezj5qq35k688.gif "/>

Four-time disconnection:

The ① client sends a disconnect request, and the server side receives the request, which is the first disconnection.

The ② server responds to the request and sends a disconnect request to the client, which is the second disconnection.

The ③ client receives a server-side disconnect request, which is the third disconnection.

The ④ client then responds to the server side, which is four disconnects.

(We can understand the disconnection process as a client-to-server disconnect and a server-side disconnect from the client, as mentioned above for the disconnected two different transport links)

650) this.width=650; "src=" Http://s1.51cto.com/wyfs02/M00/79/8B/wKiom1aUccLDDTKJAADPxEBcg4Y733.gif "title=" Four times disconnected. gif "alt=" Wkiom1aucclddtkjaadpxebcg4y733.gif "/>

Features of the TCP protocol:

Establish connection: three handshake;

Package data into segments: checksum (CRC32)

Confirmation, retransmission and timeouts;

Sort: logical Sequence number;

Flow control: Sliding window algorithm;

Congestion control: Slow start and congestion avoidance algorithms


TCP FSM (finite state mechanism of TCP): CLOSED, Listen,syn_sent, SYN_RECV, established, Fin_wait1, close_wait, Fin_wait2, Last_ack, Timewai T

Web server-based sockets and TCP protocols

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.