TCP/IP socket notes

Source: Internet
Author: User

Networks are classified from bottom to top

Physical Layer, data link layer, network layer, transmission layer, Session Layer, presentation layer, and application layer.

Through preliminary understanding, I know that the IP protocol corresponds to the network layer, the TCP protocol corresponds to the transmission layer, and the HTTP protocol corresponds to the application layer,

Essentially, they are not comparable,

Socket is the encapsulation and Application of TCP/IP protocol (programmer level ).

It can also be said that the TPC/IP protocol is a transport layer protocol that mainly addresses how data is transmitted over the network,

HTTP is an application layer protocol, mainly used to package data.

The relationship between TCP/IP and HTTP is easy to understand:

"When transmitting data, we can only use the (Transport Layer) TCP/IP protocol. However, without the application layer, we cannot identify the data content.

To make the transmitted data meaningful, you must use the application layer protocol.

There are many application-layer protocols, such as HTTP, FTP, and telnet. You can also define the application-layer protocol by yourself.

The Web uses HTTP as the application layer protocol to encapsulate HTTP text information, and then uses TCP/IP as the transport layer protocol to send it to the network ."

What is the most commonly used socket? In fact, socket is the encapsulation of the TCP/IP protocol. The socket itself is not a protocol, but a call interface (API ).

Through socket, we can use the TCP/IP protocol.

In fact, the socket and TCP/IP protocols are not necessarily related.

The socket programming interface is designed to adapt to other network protocols.

Therefore, the appearance of socket only makes it easier for programmers to use the TCP/IP protocol stack. It is an abstraction of the TCP/IP protocol,

This forms some of the most basic function interfaces we know, such as create, listen, connect, accept, send, read, and write.

The network has a saying that the relationship between socket and TCP/IP is easier to understand:

"TCP/IP is just a protocol stack. Just like the operating mechanism of the operating system, it must be implemented in detail and provide external operation interfaces.

This is just like the operating system provides standard programming interfaces, such as Win32 programming interfaces,

TCP/IP also provides interfaces that programmers can use for network development. This is the socket programming interface ."

I can't think of TCP/IP protocol too much. I just need to check the number of documents about this type of information and books on the Internet,

I plan to purchase some classic books (for example, "TCP/IP details: Volume 1, Volume 2, and volume 3") for learning, today, I will summarize some knowledge about TCP/IP-based applications and programming interfaces, that is, a lot of HTTP and socket.

Csdn has a more vivid description: HTTP is a car that provides a specific form of encapsulation or display data; socket is an engine that provides network communication capabilities.

In fact, the TCP at the transport layer is based on the IP protocol at the network layer, while the HTTP protocol at the application layer is based on the TCP protocol at the transport layer, and the socket itself is not a protocol, as mentioned above, it only provides an interface for TCP or UDP programming.

The following are some important concepts that we often encounter during the written examination or interview. Here we will extract and summarize them.

1. What is the three-way handshake of a TCP connection?

The first handshake: the client sends the SYN Packet (SYN = J) to the server and enters the syn_send status, waiting for confirmation from the server;

The second handshake: when the server receives the SYN packet, it must confirm the customer's Syn (ACK = J + 1) and send a SYN Packet (SYN = K), that is, the SYN + ACK packet, the server enters the syn_recv status;

The third handshake: the client receives the server's SYN + ACK package and sends the ACK (ACK = k + 1) Confirmation package to the server. After the package is sent, the client and server enter the established status, complete three handshakes.

The package transmitted during the handshake does not contain data. After the three-way handshake is completed, the client and the server formally start to transmit data.

Ideally, once a TCP connection is established, the TCP connection will remain until either of the two parties closes the connection.

When a TCP connection is disconnected, both the server and client can initiate a request to disconnect the TCP connection. The disconnection process must go through the "Four handshakes" (the process is not detailed, that is, the server interacts with the client, final confirmation of disconnection)

2. Use SOCKET to establish a network connection

To establish a socket connection, you must have at least one socket. One of them runs on the client, which is called clientsocket, And the other runs on the server, which is called serversocket.

The connection process between sockets is divided into three steps: server listening, client requests, and connection confirmation.

1. server listening: the server socket does not locate the specific client socket, but is waiting for connection. It monitors the network in real time and waits for the client connection request.

2. client request: the client socket initiates a connection request. The target is the server socket.

Therefore, the client socket must first describe the socket of the server to be connected, point out the address and port number of the socket on the server, and then submit a connection request to the socket on the server.

3. Connection Confirmation: when the server socket monitors or receives a connection request from the client socket, it responds to the request from the client socket and creates a new thread, send the description of the server socket to the client. Once the client confirms the description, both parties establish a connection.

The server socket continues to be in the listening status, and continues to receive connection requests from other client sockets.

Iii. Features of HTTP links

The HTTP protocol, Hypertext Transfer Protocol, is the foundation of Web networking and one of the commonly used protocols for mobile phone networking. HTTP is an application built on the TCP protocol.

The most notable characteristic of HTTP connection is that each request sent by the client requires a server to send a response. After the request ends, the connection is released. The process from establishing a connection to closing a connection is called "One connection ".

4. Differences Between TCP and UDP (most tested .. I think it's getting worse --\\)

1. TCP is link-oriented. Although network instability and instability determine the number of handshakes, the connection reliability cannot be guaranteed, however, TCP's three-way handshake ensures the connection reliability to a minimum (which is actually guaranteed to a great extent;

UDP is not connection-oriented. UDP does not establish a connection with the other party before transmitting data, nor does it send a confirmation signal for the data received. The sender does not know whether the data will be correctly received, of course, there is no need to resend, so UDP is a connectionless and unreliable data transmission protocol.

2. Due to the features described in section 1, the UDP overhead is smaller and the data transmission rate is higher, because it does not need to confirm the sending and receiving data, so UDP has better real-time performance.

Knowing the difference between TCP and UDP makes it hard to understand why MSN using TCP transmission protocol is slower than QQ using UDP, but it cannot be said that QQ communication is insecure,

Because programmers can manually send and receive UDP data for verification, such as the sender serial number of each data packet and then the Receiver performs verification,

Even so, UDP does not use a TCP-like "three-way handshake" in the encapsulation of the underlying protocol to achieve the transmission efficiency that TCP cannot achieve.

 

Supplement: http://goodcandle.cnblogs.com/archive/2005/12/10/294652.aspx

TCP/IP socket notes

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.