Qt套接字缓冲区数据怎么样清空?

C++语言 码拜 9年前 (2015-11-12) 3791次浏览
Qt中有什么东西可以让套接字缓冲区的数据清空吗?
本人从服务端接收了一个文件后;接收第二个文件,读取服务端发过来的文件数据大小时候,读取文件数据大小读出来的全是乱码;也就是说,本人之前第一个文件的数据还在呢;
不知道有没有什么方法可以让缓冲区清空啊;;;
各路神仙救命啊~!
解决方案:10分
笨方法:readAll
服务端设计有问题
解决方案:10分
 C/S ,首先你要确定,有效数据(有效包体)。 每个包的长度,C/S双方都应该知道。
格式: 包长+协议号+版本号+ 数据  (版本和协议号本人决择..)
解决方案:10分
你确定你的数据包的协议设计得正确?
你的数据包,携带了多大的数据等等,对两端来说都应该是透明的。
网络数据发送,都需要序列化(流的概念)。流化过程中,需要把数据包携带的数据类型,数据长度等都到写入,以便对端解析。
socket本身不分是QT的还是Windows的。在传输上没有什么区别。
解决方案:10分
1. 不需要什么结束符,你用十六进制编辑器看吧
2.  取决与connect
When a signal is emitted, the slots connected to it are usually executed immediately, just like a normal function call. When this happens, the signals and slots mechanism is totally independent of any GUI event loop. Execution of the code following the emit statement will occur once all slots have returned. The situation is slightly different when using queued connections; in such a case, the code following the emit keyword will continue immediately, and the slots will be executed later.
假如是上面所说的第一种情况,多个signal出现,则会出现slot被多次调用,也就是一般所说的同时运行,第二种情况按队列顺序执行  (当然结论只是猜测)
3. 全部读  当然不包括将来发来的包

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明Qt套接字缓冲区数据怎么样清空?
喜欢 (1)
[1034331897@qq.com]
分享 (0)