Socket (socket) IP TCP UDP HTTP

Source: Internet
Author: User

Socket (socket)

(turn) What is a socket (socket)?

When the application layer communicates data through the transport layer, TCP and UDP encounter problems that simultaneously provide concurrent services for multiple application processes . Multiple TCP connections or multiple application processes may require data to be transmitted over the same TCP protocol port. to differentiate between different application processes and connections , many computer operating systems provide an interface for applications to interact with the TCP/IP protocol, known as sockets (socket is the interface provided by the operating system) . Differentiate between the network communication and connections between different application processes.
Raw sockets, there are 3 main parameters: The destination IP address of the communication, the Transport Layer Protocol (TCP or UDP) used, and the port number used. The socket is intended to be "socket". By combining these 3 parameters with a "socket" socket binding, the application layer can and the transport layer through the socket interface, distinguish the communication from different application processes or network connections, to achieve the concurrent service of data transmission.
The socket can be seen as an endpoint in a communication connection of two programs, and a program writes a piece of information to the socket, which sends the message to another socket so that the message can be transferred to other programs. 1:

Program A on host a writes a piece of information to the socket, and the contents of the socket are accessed by the network management software of host A, and the information is sent to host B,host B via the network interface card of host A to receive this information. B's network management software, the network management software to save this information in the socket of Host B, and then program B to read this information in the socket. The
to communicate over the Internet requires at least a pair of sockets, one running on the client side, called Clientsocket, and the other running on the server side, called ServerSocket.
Depending on how the connection is started and the destination to which the local sockets are connected, the connection between sockets can be divided into three steps: Server listening, client request, connection acknowledgement.
Server Listener: Is the server side socket does not locate the specific client socket, but is in the state of waiting for the connection, real-time monitoring network status.
Client request: Refers to a connection request made by the client's socket, and the target to connect to 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.
Connection acknowledgement: Refers to the server-side socket to hear or receive a client socket connection request, it responds to the client socket request, set up a new thread, the server-side socket description to the client, once the client confirms the description, the connection is established. While the server-side socket continues to be in the listening state, it continues to receive connection requests from other client sockets.

And what we usually say the most socket is what, in fact, the socket is the TCP/IP protocol encapsulation, thesocket itself is not a protocol, but a call interface (API). With 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. The network has a paragraph about the socket and TCP/IP protocol relationship is easier to understand: "TCP/IP is a protocol stack, like operating system operation mechanism, must be specific, but also to provide external operating interface." This is like the operating system will provide a standard programming interface, such as the Win32 programming interface, TCP/IP should also provide the interface for programmers to do network development, this is the socket programming interface. ”

IP TCP UDP HTTP

What is the difference between TCP/IP, Http, and sockets?

The IP protocol corresponds to the network layer, the TCP protocol corresponds to the transport layer, and the HTTP protocol corresponds to the application layer.

TCP UDP is located in the transport layer, which solves the problem of how to transfer

HTTP is an application-layer protocol that primarily addresses how data is packaged

"We are when transferring data, you can use only(Transport Layer) TCP/IP protocol, but in that case, if data content cannot be recognized without an application layer (only the transport layer can transmit data, but no application layer will recognize the data)。 If To make the transferred data meaningful, you must use the application-layer protocol。 There are many application layer protocols, such as HTTP, FTP, Telnet, etc., and you can define the application layer protocol yourself. The web uses the HTTP protocol as an application-layer protocol to encapsulate HTTP text information and then send it to the network using TCP/IP as the Transport layer protocol. ”

The TCP of the transport layer is based on the IP protocol of the network layer, and the HTTP protocol of the application layer is based on the TCP protocol of the Transport layer, and the socket itself is not a protocol, as stated above, it just provides an interface for TCP or UDP programming.

The difference between TCP and UDP

1, TCP is a link-oriented , although the security of the network instability characteristics determine how many times the handshake can not guarantee the reliability of the connection, but the TCP three handshake at a minimum (in fact, to a large extent guaranteed) to ensure the reliability of the connection;

And UDP is not connection-oriented , UDP transmission data before the connection with the other, the docking received data does not send a confirmation signal, the sender does not know whether the data will be received correctly, of course, there is no need to resend, so that UDP is a non-connected, unreliable data transmission protocol.

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

Know the difference between TCP and UDP, it is not difficult to understand why the use of TCP transmission protocol MSN than UDP transmission file slow, but can not say that QQ communication is not safe,

Because programmers can manually authenticate UDP data, such as the sender of each packet number and then by the receiver to verify ah what?

Even so, UDP does not have a TCP-like "three-time handshake" on the package of the underlying protocol to achieve the transmission efficiency that TCP cannot achieve.

Socket (socket) IP TCP UDP HTTP

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.