当前位置:网站首页>QT client socket qtcpsocket specifies the local IP through bind
QT client socket qtcpsocket specifies the local IP through bind
2022-06-11 00:12:00 【Big orange】
background :
I do a PC software , It is necessary to control several slave computers at the same time , Use socket communication . But in the production stage, I don't want to always use the computer for debugging , Instead, the communication process is simulated locally .
The local network card can specify multiple ip Address , I want the client to ( Analog slave computer ) Connect server ( Simulate the upper computer ) when , Be able to specify ip And port . So when connecting , To identify which lower computer it is . The lower computer cannot be designed to send a packet to confirm its identity after connecting . At least for now, I don't want the lower computer to make changes , But I do it myself on the upper computer .
Follow the help instructions to use QTcpSocket Class bind Functions can be bound to ip And port , That is to designate . But in fact, once you get to the port , There will be all kinds of discomfort .
When you do not need to identify the client , Don't worry about it. , The client will be based on its own host ip, Automatically select random port . At this time, it is flexible to connect and disconnect casually , Without any influence .
Once bound ip And port , It is not allowed to disconnect and reconnect frequently . Various online methods , Just listen to the socket and don't use it directly QTcpServer, To pass the API call . Or port multiplexing .
In fact, it doesn't apply to me . apply Qt To cross platform , Don't want to try to talk to OS Relevant specific API. Port multiplexing is important for qt In fact, it is not very flexible , Still have to wait OS Response .
resolvent :
Limited to my needs , Just be able to identify the client .
It's simple , Use bind Binding time , Bind only ip That's it , Ports let it be random . There can be several more local network cards ip, Each client specifies one ip, Regardless of port . More efficient .
Be careful :
qt It's a bit of a hole set function , such as setPeerName,setLocalAddress etc. , First of all protect type , You need to write a subclass to call indirectly . Even if it can be called, it will not happen , These functions are only used to set the return value of some functions , It has little significance in practical application . Or it doesn't mean much to my needs .
Often these set Functions can be misleading , No set I will be able to get.
边栏推荐
- How to measure the refresh rate of oscilloscope
- 安全生产月,黄埔开展燃气安全进商铺宣传活动
- 【Opencv实战】这个印章“神器”够牛,节省了时间提高了效率,厉害~(附完整源码)
- MySQL命令行导入导出数据
- A simple understanding of B tree
- [opencv practice] in cold winter, there will be a rainbow. Do you love this special effect?
- OpenResty安装
- Lambda 学习记录
- [pyGame games] in the first month, it broke 100 million to download a masterpiece that is highly integrated with "super casual game features"~
- WinDriver compilation summary
猜你喜欢

USB IP core FPGA debugging (I)

【Pygame小游戏】首月破亿下载 一款高度融合了「超休闲游戏特性」的佳作~

Things about Bluetooth development (1) -- starting with packet capturing data
![[pyGame games] tank battle, how many childhood games do you remember?](/img/30/951fdbb944e026701af08c0c068cd8.png)
[pyGame games] tank battle, how many childhood games do you remember?

【Opencv实战】寒冷的冬季,也会迎来漫天彩虹,这特效你爱了嘛?
![[untitled]](/img/7e/aab9560ef5a1b93f737a82561ec114.png)
[untitled]
![[pyGame games] story stream recommendation: what kind of games can you like? (devil lover, bully's wife version)](/img/77/653968895434f805d81a10406dcf6f.png)
[pyGame games] story stream recommendation: what kind of games can you like? (devil lover, bully's wife version)

csdn每日一练——有序表的折半查找

安全生产月,黄埔开展燃气安全进商铺宣传活动

博文推荐|构建 IoT 应用——FLiP 技术栈简介
随机推荐
Opencv实战之图像的基本操作:这效果出来惊艳了众人(附代码解析)
【Pygame小游戏】趣味益智游戏 :打地鼠,看一下能打多少只呢?(附源码)
[turtle confessions collection] "the moon at the bottom of the sea is the moon in the sky, and the person in front of us is the sweetheart." Be happy for the rest of your life, and be safe for ever ~
Several common current transformer sampling circuits
B 树的简单认识
什么是绝对和相对路径,有哪些优缺点?
vtk. VTP download in JS
mysql 数据库 表 备份
Multipartfile rename upload
Collection delete element technique removeif
[fireworks in the sky] it's beautiful to light up the night sky with gorgeous fireworks. A programmer brought a fireworks show to pay New Year's greetings to everyone~
mybaits merge into
ASP. Net programming version C (notes along with learning progress)
CSDN daily practice -- half search of ordered table
C language file operation
2022年高考量化卷|请各位量化考生答题
Quick sort
【Pygame小游戏】这款经典的炸弹人超能游戏上线,你爱了嘛?(附源码)
Bluetooth development (8) -- avdtp connection process
csdn每日一练——有序表的折半查找