Brief introduction of Socket,ip,tcp three-time handshake, HTTP protocol (for understanding, memory and learning)

Source: Internet
Author: User
Tags ack

I am here to briefly describe socket,ip,tcp three handshake, HTTP protocol (useful for understanding, remembering and learning the interview for easy answers)

1. Socket principle

Socket support on-line point-to-point communication
Service, the end of the service to realize the listening connection. The client implements the send connection request, and sends and receives data after the connection is established.
Server-side build a serversocket. Set the IP of the machine and the listening port to bind with the socket, and start listening to the connection request, when the connection request is received, send a confirmation, establish a connection with the client. Start to communicate with the client.


Client to create a socket. Set the server-side IP and port that provides the service. A connection request is made, after the acknowledgement of the server is received. Try to connect and start communicating with the server.
The server side and client connections and the data transfer between them are synchronized.
2. IP
IP is a non-connected protocol, primarily responsible for addressing between hosts and routing packets, and it does not establish a session before exchanging data. Because it does not guarantee the correct delivery, and on the one hand, when the data is received, IP does not need to receive confirmation, so it is unreliable
3. TCP
TCP is a reliable connection-oriented delivery service. It is segmented when the data is transferred, and the host Exchange data must establish a session. It uses bits to circulate the letter, that is, the data is used as a non-structured byte stream.


Specify the order number by the field that each TCP transmits. To achieve reliability.

Assuming that a segment is decomposed into a few small segments, the receiving host knows if all the small segments have been received. By sending an answer to confirm that the other host received the data. For each small segment sent, the receiving host must return an acknowledgment at a specified time.

Assuming the sender does not receive confirmation, the data is sent again. Assume that the received packet is corrupted. Receives the master opportunity to discard it because the acknowledgment was not sent. The sender will send the segment again.


Port
The sockets utility uses a protocol port number to indicate the uniqueness of its own application.

The port can use no matter what the number is between 0 and 65536. When the service is requested. The operating system dynamically assigns the port number to the client's application.


Sockets
Sockets are similar to file handles on the essentials, because they function as endpoints for network traffic.

An application produces a socket by defining three parts: the host IP address, the type of service (the connection-oriented service is TCP, no connection service is UDP), and the port used by the application.




TCPport
TCPPort provides a place for the transmission of information. The port number less than 256 is defined as the frequent use of port.


Three-time handshake for TCP
The TCP conversation is initialized by a three-time handshake.

The purpose of the three-time handshake is to synchronize the sending and receiving of data segments, to tell other hosts how much data they can receive at one time, and to establish virtual connections.


Let's take a look at the simple process of shaking hands three times:
(1) The initialization host sends a session request through a data segment with a synchronous flag set.
(2) The receiving host responds by sending back data segments that have the following items: The synchronization flag is set, the sequence number of the starting byte of the data segment to be sent, and the reply with the byte order number of the next data segment that will be received.
(3) requesting the host to return a data segment with confirmation sequence number and confirmation number.


The bit code is the TCP flag bit, there are 6 kinds of marking: SYN (synchronous set up) ACK (acknowledgement acknowledgment) PSH (push transfer) FIN (finish end) RST (reset reset) URG (Urgent emergency)


Sequence number (sequential) Acknowledge number (confirmation)


First handshake: Host A sends a bit code of syn=1, randomly generates a SEQ number=1234567 packet to the server, Host B is known by Syn=1, a requires to be established online.


Second handshake: Host B confirms the online information after it receives the request. Send Ack number= (host A's seq+1) to a, syn=1,ack=1, randomly generate seq=7654321 packets


Third handshake: When host A is received, check that the ACK number is correct. That is, the SEQ number+1 that was sent for the first time, and whether the bit code ACK is 1. If correct. Host A will then send an ACK number= (Host B's seq+1), ack=1, and Host B acknowledges that the SEQ value is connected to ack=1 when the connection is established successfully.


After three handshake, host A and Host B start transmitting data.
4. HTTP protocol
The main features of the HTTP protocol can be summarized such as the following:
1. Support Customer/server mode.


2. Simple high-speed: When a client requests a service from the server, it simply transmits the request method and path.

The request method is often used with, and POST. Each method specifies that the customer has a different type of contact with the server.

Because the HTTP protocol is simple. This makes the Httpserver program small, thus communication speed is very fast.
3. Flexible: HTTP agrees to transfer arbitrary types of data objects. The type being transmitted is marked by Content-type.
4. No connection: The meaning of no connection is to limit each connection to just one request. When the server finishes processing the customer's request and receives the customer's answer, the connection is disconnected. In this way, the transmission time can be saved.


5. Stateless: The HTTP protocol is a stateless protocol. Stateless means that the protocol has no memory capacity for transactional processing.

A lack of state means that assuming that the preceding information may be processed, it must be re-routed, which could result in an increase in the amount of data sent per connection. On the other hand, when the server does not need the previous information, it responds faster.

Brief introduction of Socket,ip,tcp three-time handshake, HTTP protocol (for understanding, memory and learning)

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.