套接字混合或丢失数据???? [英] Sockets Mixing or Losing Data????

查看:104
本文介绍了套接字混合或丢失数据????的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,我要说我已经与Winsock打交了很多年,并试图将我的项目从vb6转换为VB.Net.

该程序旨在一次处理多达70个连接,并不断地将数据从Server发送到客户端,然后再发送回客户端.



但是有一个数据包,发送时可达177kb左右.套接字设置为一次发送1kb....(没有其他数据包实际使用整个kb).看来在服务器发送完这个大数据包之后……客户端接收到的数据是乱序的.在调试和监视之后,我发现它通常发生在3-4kb之间.前三个很好,而且顺序良好.



我的问题是,是否应该使用其他系统而不是仅使用套接字(我在TCPClient上遇到过类似的问题),并且/或者有人可以将我链接到一个不会出现此错误的示例项目?


First let me start off by saying that I have dealt with Winsock for MANY years and am attempting to convert my project over from vb6 to VB.Net.

This program was made to handle up to 70 connections at a time and constantly sending data from Server to clients and back.



There is one packet however, that reaches up to be around 177kb when sent. The sockets are set up to sent 1kb at a time.... (No other packet actually uses the whole kb). It seems that after the server sends this large packet... the client receives the data out of order. After debugging and monitoring I find that it normally happens between 3-4kb. While the first 3 are good and in order.



My question is, is there a different system I should use instead of just Sockets (I have had similar problems with TCPClient) and/or can someone maybe link me to a sample project that would not have this error?



Thanks!

推荐答案

仅使用套接字(仅IP)时,可能会乱序接收数据报.使用传输控制层时,请确保这些数据报的段是有序的.您应该在两端使用TCP来确保其正常工作.您提到使用TCPClient,但同时也使用TCPServer吗?使用TCP时,解决了乱序接收数据的问题.

祝你好运!
When just using sockets (just IP) it is possible for receiving datagrams out-of-order. When using the Transport Control Layer the segments of these datagrams are ensured to be in-order. You should use TCP on both ends to ensure that it works correct. You mention that you use TCPClient but do you also use TCPServer? When using TCP the problem of receiving data out-of-order is solved.

Good luck!


这篇关于套接字混合或丢失数据????的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆