当前位置:网站首页>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.
边栏推荐
猜你喜欢
随机推荐
Scala 加密和哈希函数
MES对接Simba实现展讯平台 IMEI 写号与耦合测试
Unity ScrollView无限循环左右滑动翻页带阻尼效果
2020-03-09
2020-03-09
远程调试为何要亲历现场,也许也可以这样解决
windows10安装vagrant+VirtualBox搭建PHP开发环境
U disk cannot be displayed on computer
我曾七次鄙视自己的灵魂——纪伯伦
腾讯技术支持实习二面——腾讯爸爸的临幸就是这么突然(offer到手)
【计网】(五)网络层首部
选择排序
UGUI性能优化
软件设计原则
论文阅读 (66):Explainable Deep Feature Embedding Using Multiple Instance Learning for Pathological Image
2.5W 字详解线程与锁了,面试随便问!!
Unity 创建重复使用的子节点,避免生成多个子节点
ALIPAY WEB 登陆rsa加密 分析记录
同花顺的炒股软件买股票安全正规可信吗?
A letter, a Chinese each have how many bytes