当前位置:网站首页>The Socket (Socket)
The Socket (Socket)
2022-08-08 22:35:00 【Carry,】
Overview
When the application layer communicates data through the transport layer, TCP and UDP encounter the problem of providing concurrent services to multiple application processes at the same time.Multiple TCP connections or multiple application processes may need to transmit data over the same TCP protocol port.In order to distinguish different application processes and connections, many computer operating systems provide interfaces called sockets for the interaction between applications and the TCP/IP protocol to distinguish network communication and connections between different application processes.
To generate a socket, there are mainly three parameters: the destination IP address of the communication, the transport layer protocol (TCP or UDP) used and the port number used.The original meaning of Socket is "socket".By combining these three parameters and binding with a "socket" Socket, the application layer can communicate with the transport layer through the socket interface, distinguish the communication from different application processes or network connections, and realize the concurrent service of data transmission.
Socket classification
- Streaming sockets.
It provides a reliable, connection-oriented two-way data transmission service, and realizes the data transmission without error and repetition.Stream sockets have built-in flow control, and the transmitted data is treated as a stream of bytes without record boundaries.In the TCP/IP protocol suite, the TCP protocol is used to realize the transmission of byte streams. When the user wants to send a large amount of data or has higher requirements for data transmission, the stream socket can be used. - Datagram socket.
It provides a connectionless, unreliable two-way data transfer service.Packets are sent in independent form, and record boundaries are preserved, with no reliability guarantees.Data may be lost or duplicated during transmission, and there is no guarantee that data will be received at the receiving end in the order sent.In the TCP/IP protocol suite, the UDP protocol is used to implement datagram sockets.In applications where the possibility of errors is small or some transmission errors are allowed, datagram sockets can be used for data transmission, so that the communication efficiency is higher. - Raw sockets.
This socket allows direct access to lower layer protocols such as IP or ICMP and is often used for network protocol analysis, to verify new network protocol implementations, and to test newly configured or installed network devices.
socket communication process

- The server creates a socket according to the address type (ipv4, ipv6), socket type, and protocol.
- The server binds the ip address and port number to the socket.
- The server socket listens for port number requests and is ready to receive connections from clients at any time. At this time, the server socket is not opened.
- The client creates the socket.
- The client opens the socket and tries to connect to the server socket according to the server ip address and port number.
- The server socket receives the client socket request, passively opens it, and starts to receive client requests until the client returns the connection information.At this time, the socket enters the blocking state. The so-called blocking means that the accept() method does not return until the client returns the connection information, and starts to receive the next client connection request.
- The client connects successfully and sends the connection status information to the server.
- The server accept method returns and the connection is successful.
- The client writes information to the socket.
- Server reads information.
- Client closed.
- Server side shutdown.
边栏推荐
猜你喜欢
随机推荐
2020-03-09
彻底理解 volatile 关键字及应用场景,面试必问,小白都能看懂!
微服务架构的核心关键点
一个PHP算法,php数组一个二维数组拆分成多个子数组
股市预测,销量预测,病毒传播...一个时间序列建模套路搞定全部!
Sql注入以及靶场演示
U disk cannot be displayed on computer
Unity BMFont自定义字体
Hands-on Deep Learning_Transposed Convolution
新安装Laravel Framework 6.18.35 php artisan migrate 报错
php7.4安装ssh2扩展和使用ssh链接sftp上传下载文件
win10电脑安装Photoshop cs7软件版本
2020-03-09
腾讯技术支持实习二面——腾讯爸爸的临幸就是这么突然(offer到手)
我曾七次鄙视自己的灵魂——纪伯伦
应用层协议——RADIUS
Unity工程安全地修改脚本名、变量名,不丢失现有的引用
MySQL8.0 及 SQL 注入
IMConversation 或 IMUser 类型数据
laravel6框架跨域请求利器之 Laravel CORS 扩展包的安装和使用







![17 [2D conversion 3D conversion browser private prefix]](/img/d0/2b310e6b6b375d457f339a6a9d71e1.png)

