What is a socket and why use a socket

Source: Internet
Author: User

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 called socket (socket) for applications interacting with the TCP/IP protocol, differentiating network traffic 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.

To communicate over the Internet, you need 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 socket is connected, the connection between sockets can be divided into three steps: Server listening, client request, connection acknowledgement.
Server monitoring: Is the server side socket does not locate the specific client socket, but 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 destination of the connection 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 confirmation: When a server-side socket is heard or received 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 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.

Collected in 2011-05-24 from the Baidu space

What is a socket and why use a socket

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.