当前位置:网站首页>三次握手的Socket交互流程
三次握手的Socket交互流程
2022-07-27 20:43:00 【华为云】
共享内存
共享内存是针对其他通信机制运行效率较低而设计的,它可以让多个进程可以可以直接读写同一块内存空间,是最快的IPC形式。
为了在多个进程间交换信息,内核专门留出了一块内存区,可以由需要访问的进程将其映射到自己的私有地址空间。进程就可以直接读写这一块内存而不需要进行数据的拷贝,从而大大提高效率。
由于多个进程共享一段内存,因此需要依靠某种同步机制来达到进程间的同步和互斥。
信号量
信号量是一个计数器,可以用来控制多个进程对共享资源的访问。它是一种类似于锁的机制,就是防止某进程正在访问共享资源时,其他进程也访问该资源。参考这里。
Socket
Socket就是套接字,套接字也是一种通信机制,凭借这种机制,可以让不在同一台主机上的两个进程,通过网络进行通信,一般可以用在客户端和服务器之间的通信。
实际上,Socket 是在应用层和传输层之间的一个抽象层,它把 TCP/IP 协议的传输层里面复杂的操作,抽象为几个简单的接口,供应用层调用实现进程在网络中的通信。
延伸问题:Socket通信流程是怎样的?
概括地说,就是通信的两端都建立了一个 Socket ,然后通过 Socket 对数据进行传输。通常服务器处于一个无限循环,等待客户端的连接。
对于客户端,它的的过程比较简单,首先创建 Socket,通过TCP连接服务器,将 Socket 与远程主机的某个进程连接,然后就发送数据,或者读取响应数据,直到数据交换完毕,关闭连接,结束 TCP 对话。
对于服务端,先初始化 Socket,建立流式套接字,与本机地址及端口进行绑定,然后通知 TCP,准备好接收连接,调用 accept() 阻塞,等待来自客户端的连接。如果这时客户端与服务器建立了连接,客户端发送数据请求,服务器接收请求并处理请求,然后把响应数据发送给客户端,客户端读取数据,直到数据交换完毕。最后关闭连接,交互结束。
延伸问题:从TCP连接的角度说说Socket通信流程。
首先是三次握手的Socket交互流程。
服务器调用 socket()、bind()、listen() 完成初始化后,调用 accept() 阻塞等待;
客户端 Socket 对象调用 connect() 向服务器发送了一个 SYN 并阻塞;
服务器完成了第一次握手,即发送 SYN 和 ACK 应答;
客户端收到服务端发送的应答之后,从 connect() 返回,再发送一个 ACK 给服务器;
服务器 Socket 对象接收客户端第三次握手 ACK 确认,此时服务端从 accept() 返回,建立连接。
接下来就是两个端的连接对象互相收发数据。
然后是四次挥手的Socket交互流程。
某个应用进程调用 close() 主动关闭,发送一个 FIN;
另一端接收到 FIN 后被动执行关闭,并发送 ACK 确认;
之后被动执行关闭的应用进程调用 close() 关闭 Socket,并也发送一个 FIN;
接收到这个 FIN 的一端向另一端 ACK 确认。
边栏推荐
- Cloudcompare & PCL platform convex hull method to calculate crown volume
- 你的列表很卡?这4个优化能让你的列表丝般顺滑
- 微信安装包11年膨胀575倍,UP主:“98%的文件是垃圾”;苹果应用商店被曝大量色情App;四大科技巨头呼吁废除闰秒|极客头条
- 华为鸿蒙 3 正式发布,这个安全功能解决了一大痛点
- Cron expression
- Dry goods semantic web, Web3.0, Web3, metauniverse, these concepts are still confused? (medium)
- 台积电3nm细节曝光:晶体管密度高达2.5亿个/mm²,性能及能效大幅提升
- Network development socket and UDP, TCP protocols
- XML external entity (xxE) vulnerability and its repair method
- Containerd CTR run the ansible container and execute the complete command of ansible playbook task
猜你喜欢

Exercise --- BFS

Huawei Hongmeng 3 was officially released, and this security feature has solved a major pain point

Introduction to the paper | distributed graph simulation
![[image defogging] image defogging based on dark channel and non-mean filtering with matlab code](/img/44/6120682f9571f6ad35f8b9249b7fea.png)
[image defogging] image defogging based on dark channel and non-mean filtering with matlab code
![[image detection] realize the detection of nostrils and pupil circles based on combined separation filter matlab source code](/img/6a/92ace81b798810299a2fec0ce6ae70.png)
[image detection] realize the detection of nostrils and pupil circles based on combined separation filter matlab source code

【图像检测】基于Combined Separability Filter实现鼻孔和瞳孔等圆检测matlab源码
![[number recognition] recognize 0-9 numbers based on Hopfield neural network with matlab code](/img/10/de712b67a7538be03f8fb722271949.png)
[number recognition] recognize 0-9 numbers based on Hopfield neural network with matlab code

Cron expression

华为鸿蒙 3 正式发布,这个安全功能解决了一大痛点

深入了解 XXE 注射
随机推荐
What are the advantages of Tita's OKR system over other similar products or shared documents?
Google executives: 40% of "generation Z" are more willing to use tiktok to cannibalize Google's core products
VIM editor tutorial
[C language] simulate and implement string functions (Part 1)
【数字识别】基于知识库实现手写体数字识别附matlab代码
Lianmai live broadcast system software - voice chat system
编辑复制粘贴判定问题(bug?),所见即所得显示符号问题反馈。
Library management system based on SSM framework
Microsoft Office 2019 download installation activation tutorial (full process diagram)
CSDN dedicated killer technology -- Google browser plug-in
深入了解 XXE 注射
Software test function test full set of common interview questions [function test] interview summary 4-2
The prefix is not removed when zuul gateway automatically routes
Arm32 for remote debugging
ELK日志分析系统安装和部署
The print version of imeta | international standard ISSN is officially confirmed, and the application for dual ISSN is completed
Keming food: the average increase in the sales price of various series of products is about 5%
软件测试功能测试全套常见面试题【功能测试】面试总结4-2
Desai wisdom number - other charts (parallel coordinate chart): family's willingness to allocate assets in the future
reduce错误示范