Socket connection and HTTP connection

Source: Internet
Author: User
Tags ack

Socket Connect to an HTTP connection

When we transmit data, we can only use (Transport layer)Tcp / ipprotocol, but in that case, if there is no application layer, the data content is not recognized, if you want to make the transferred data meaningful, you must use to the Application layer protocol, the application layer protocol has many, such asHTTP、Ftp、telnetweb use http protocol as application layer protocol to encapsulate http text information, then use tcp/ip
1) Sockettcpudp programming interface, you can use it to establish tcp connection and so on. and tcp and udp protocol belongs to transport layer  < Span class= "S1".
  http is an application layer protocol , it is actually built on the tcp protocol. &NBSP;

(HTTP is a sedan that provides a specific form of encapsulation or display of data; theSocket is the engine that provides the ability to communicate on the network.) )

2)socket is the TCP/IP protocol encapsulation, thesocket itself is not a protocol, but a call interface (API), through the socket , we can use the TCP/IP protocol. The advent of sockets only 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.

Here are some of the important concepts, special here to do excerpts and summaries.

A. What is a Three-time handshake for a TCP connection

First handshake: Client sendssyn package (SYN=J) to server, and enter syn_ Send status, waiting for server confirmation;
second handshake: Server received syn package, you must confirm the customer's syn (ack=j+1syn package (syn=ksyn +acksyn_recv status;
Third handshake: client receives server syn+ack package, Send confirmation package to server ack (ack=k+1) established

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 aTCP 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)

two. to establish a network connection using a Socket

Establishing A socket connection requires at least one pair of sockets, one running on the client, called Clientsocket , and the other running on the server side, called ServerSocket .

The connection between sockets is divided into three steps: Server listening, client request, connection acknowledgement.

1. Server monitoring: Server-side sockets do not locate specific client sockets, but are waiting for the status of the connection, real-time monitoring network status, waiting for the client connection request.

2. Client request: Refers to the client's socket to make a connection request, to connect to the target is the server-side socket. To do this, the client's socket must first describe the socket of the server it is connecting to, indicate the address and port number of the server-side socket, and then make a connection request to the server-side socket.

3. Connection confirmation: When a server-side socket hears or receives a connection request from a client socket, it responds to a client socket request, establishes a new thread, sends a description of the server-side socket to the client, and once the client confirms the description, the two sides formally establish the connection. While the server-side socket continues to be in the listening state, it continues to receive connection requests from other client sockets.

three. features of HTTP links

The HTTP protocol, the Hypertext Transfer Protocol (hypertext Transfer Protocol), is the foundation of Web Networking and one of the most commonly used protocols for mobile networking, which is built on an application above the TCP protocol.

The most notable feature of an HTTP connection is that each request sent by the client requires a server loopback response, and the connection is actively released after the request has ended. The process from establishing a connection to closing a connection is called a " one-time connection ."

Four. The difference between TCP and UDP

1. TCP is link-oriented, although the insecure nature of the network determines how many times the handshake can not guarantee the reliability of the connection, but the TCP three-time handshake at least (in fact, to a large extent guaranteed) to ensure the reliability of the connection, and UDP is not a connection-oriented,UDP transmission of data before the connection with the other party, the data received will not send a confirmation signal, the sender does not know whether the data will be received correctly, of course, do not have to resend, so that UDP is not connected, A data transmission protocol that is unreliable.

2. Also due to the characteristics of 1, so that the cost of UDP more small data transmission rate is higher, because there is no need to send and receive data confirmation, so UDP real-time better.

Socket connection and HTTP connection

Related Article

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.