Socket HTTP TCP UDP IP protocol

Source: Internet
Author: User
Tags ack

The socket can support different transport layer protocols (TCP or UDP), which is a TCP connection when the connection is made using the TCP protocol.

The socket is an abstraction layer between the application layer and the transport layer, which abstracts the complex operations of the TCP/IP layer into a few simple interfaces to provide a layer to invoke the implemented process to communicate in the network

In fact, the socket is the TCP/IP protocol encapsulation, the socket itself is not a protocol, but a call interface (API), through the socket, we can use the TCP/IP protocol.

Socket is the TCP/IP protocol encapsulation, the socket itself is not a protocol, but a call interface (API), through the socket, we can use the TCP/IP protocol. In fact, the socket is not necessarily associated with the TCP/IP protocol. The socket programming interface is designed to adapt to other network protocols as well. So, the advent of sockets just makes it easier for programmers to use the TCP/IP protocol stack, which is an abstraction of the TCP/IP protocol, thus forming some of the most basic function interfaces we know, such as Create, listen, connect, accept, send, Read and write, and so on.

Socket Communication Process

TCP/IP protocol

    • First handshake: The client sends a SYN packet (SYN=J) to the server and enters the Syn_send state, waiting for the server to confirm;
    • Second handshake: The server receives the SYN packet, it must confirm the customer's SYN (ACK=J+1), and also send itself a SYN packet (syn=k), that is, the Syn+ack packet, when the server enters the SYN_RECV state;
    • Third handshake: The client receives the server's Syn+ack packet, sends the acknowledgment packet ack (ACK=K+1) to the server, the packet is sent, the client and the server enter the established state, and the handshake is completed three times.

The data is not included in the packets that are delivered during the handshake, and the client and server formally begin transmitting the data after the three handshake is complete. Ideally, once a TCP connection is established, the TCP connection is maintained until either side of the communication actively closes the connection. When disconnected, both the server and the client can initiate a request to disconnect the TCP connection, and the disconnection process requires a "four handshake" (the process is not fine-grained, that is, the server interacts with the client and finally determines the disconnection).

============================================================

HTTP is a short connection: the client sends a request that requires a server-side loopback response. After the request is over, the link is released actively, so it is a short connection.

As a general rule, you do not need any data, and you want to keep a "keep-connected" request to the server at regular intervals. This ensures that the client is "on the Go" state on the server side.

If the server can not receive the client's request for a long time, it is considered that the client "offline", if the client cannot receive a reply from the server for a long time, it is considered that the network has been disconnected.

The difference between HTTP and socket: One transmission is fast, one transmission is slow. But they are all based on the TCP/IP/UDP three kinds of protocols, for data transmission.

What is the case with a socket or HTTP
For example: video, images, breakpoints to continue the case to use the socket
The stateless nature of the HTTP protocol does not implement this feature.

HTTP protocol is the application layer of the semantic, there is a comparative image of the description: HTTP is a sedan, provides a specific form of encapsulation or display data; the socket is the engine that provides the ability to communicate on the network.

Socket HTTP TCP UDP IP protocol

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.