• The network is divided into physical layer, data link layer, network layer, transport layer, session layer, presentation layer and application layer from bottom to top. Through a preliminary understanding, I know that IP protocol corresponds to the network layer, TCP protocol corresponds to the transport layer, and HTTP protocol corresponds to the application layer. The three are essentially comparable, and socket is the encapsulation and application of TCP/IP protocol (programmer level). In other words, TPC/IP is a transport-layer protocol that deals with how data is transferred over the network, while HTTP is an application-layer protocol that deals with how data is packaged.
  • Colloquially: We can only use in data transmission, TCP/IP protocol (transport layer), but in that case, if there is no application layer, can’t identify the data content, if you want to make the transmission of data meaningful, it must be used in the application layer protocol, the application layer protocol has a lot of, such as HTTP, FTP, TELNET, etc., can also define your own application layer protocol. The WEB uses HTTP as an application layer protocol to encapsulate HTTP text information, and then uses TCP/IP as a transport layer protocol to send it to the network.

What is a socket?

1. In fact, the socket is the encapsulation of TCP/IP. The socket itself is not a protocol, but an API.

Tcp/ip

1. TCP/IP is just a protocol stack. Like the operating mechanism of an operating system, it must be implemented in detail and provide external operation interfaces. This is just like the operating system will provide standard programming interface, such as win32 programming interface, TCP/IP also should provide for programmers to do network development used interface, this is Socket programming interface.

oneWhat is the three-way handshake for TCP connections?

  1. First handshake: The client sends a SYN packet (SYN = J) to the server and enters the SYN_SEND state for confirmation.

  2. Second handshake: After receiving a SYN packet, the server must acknowledge the client’s SYN (ACK = J +1) and send a SYN packet (ACK = K). In this case, the server enters the SYN_RECV state.

  3. Third handshake: After receiving the SYN+ACK packet from the server, the client sends an ACK packet (ACK = K +1) to the server. After the packet is sent, the client and the server enter the ESTABLISHED state to complete the three-way handshake. The packet transmitted during the handshake does not contain data. After three handshakes, the client and server start data transmission. Ideally, once a TCP connection is established, it is maintained until either of the communicating parties voluntarily closes the connection. Both the server and the client can initiate a request to disconnect the TCP connection. The disconnection process requires a four-way handshake.

twoThe procedure for establishing a network connection using a Socket

Establishing a socket connection requires at least one pair of sockets. There are three steps for clientSocket and serverSocket:

  1. Server listening: The server socket does not locate the specific client socket, but is in the state of waiting for the connection, monitoring the network status in real time, waiting for the connection request of the client.

  2. Client request: a connection request is made by the client socket to the server socket. To do this, the client-side socket must first describe the socket of the server to which it is connecting, specifying 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 the server socket listens to or receives a connection request from the client socket, it responds to the request of the client socket by creating a new thread and sending the description of the server socket to the client. Once the client confirms the description, the two sides formally establish a connection. The server socket continues to listen, receiving connection requests from other client sockets.

3.Features of HTTP links

HTTP, also known as Hypertext Transfer Protocol, is the foundation of Web networking and one of the protocols commonly used in mobile networking. HTTP is an application based on TCP.

The most remarkable feature of HTTP connections is that each request sent by the client requires a response from the server, and when the request is complete, the connection is released. The process from establishing a connection to closing a connection is called one connection.

Four.Differences between TCP and UDP

1. TCP is link-oriented, although the insecure and unstable characteristics of the network determine how many times the handshake can not ensure the reliability of the connection, but TCP three handshake in the minimum (in fact, also to a large extent) to ensure the reliability of the connection; UDP is not connection-oriented. It does not establish a connection with the other party before transmitting data, and does not send an acknowledgement signal to the received data. The sender does not know whether the data will be correctly received and does not need to resend the data.

2. Because of the features mentioned above, UDP has a lower overhead and a higher data transfer rate. UDP is better in real time because there is no need to confirm sending and receiving data.

Understand the difference between TCP and UDP, it is not hard to understand why the TCP transport protocol is slower than the transfer files using UDP QQ MSN, but doesn’t say QQ communication is not secure, because programmers can manually to validate the UDP data transceiver, such as the sender of each packet number and then validated by the receiving party ah of what, Even so, UDP achieves the transmission efficiency that TCP cannot achieve because it does not adopt the “three-way handshake” similar to TCP in the encapsulation of the underlying protocol.