VB6 异步 Tcp 客户端截断传入消息
我有一个 C# Tcp 服务器,它将消息发送到注册的 VB6 Tcp 客户端。消息的接收是使用 WinSock 以异步方式完成的。因此,“已完成”消息出现的 VB6 部分如下所示:
Private Sub wskConnect_DataArrival(ByVal bytesTotal As Long)
Dim sBuff As String
wskConnect.GetData sBuff, vbString '-- Retrieve sent value
ProcessMessage sBuff '-- Process the value
End Sub
问题是 C# Tcp 服务器正在发送长度为 6874 的字符串,但是当我们检查 DataArrival 事件触发时收到的消息大小时,它测量结果仅为 2920。很明显,传入消息的截断是一个严重的问题。
以前有人观察过这一点吗?
I have a C# Tcp server that sends messages to registered VB6 Tcp clients. The receiving of the message is done using WinSock in an asynchronous fashion. So the VB6 part where the "completed" message comes in looks like:
Private Sub wskConnect_DataArrival(ByVal bytesTotal As Long)
Dim sBuff As String
wskConnect.GetData sBuff, vbString '-- Retrieve sent value
ProcessMessage sBuff '-- Process the value
End Sub
The problem that is that the C# Tcp server is sending a string of length 6874, but when we check the size of the message as received when the DataArrival event fires, it measure only 2920. So clearly this truncation of the incoming message is a severe problem.
Has anyone observed this before?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
正如我在这里所说的VB6 WinSock TCP客户端和.NET TCP服务器:
仅因为您在 DataArrival 上仅看到数据长度 2920,并不意味着数据已被截断。这只是意味着这就是当时可用的全部。将该数据读入缓冲区,然后当您发送的下一部分数据可用时,该事件将再次触发。继续读取可用数据并将其附加到缓冲区,直到获得完整消息。
As I said here VB6 WinSock TCP client and .NET TCP server:
Just because you only see a data length of 2920 on DataArrival doesn't mean the data was truncated. It just means that that was all that was available at that moment. Read that data into a buffer, and then when the next part of the data you sent is available the event will fire again. Continue to read the available data and append to your buffer until you have the whole message.
使用mscomm控件也存在同样的问题。
处理异步事件总是很困难。
首先这是我个人的处理方式
可能以其他更好的方式存在。所以这又多了一种选择。
我不止一次遇到这个问题,而且经常忘记如何解决
处理这个问题。所以这也是我个人的参考
首先
,我们需要了解事件是如何发生的
图形视图是死区时间,死区时间只是一个时间段
现在,在 vb6 中,当异步事件发生时,也需要在不同时刻发生两个操作,但在同一时刻进行测试
此外,我们还需要一些实用程序来跟踪我使用 win api GetTickCount 的时间。
在 mscomm 中,我们还需要添加标志和字符串,以了解是否收到了一些信息不用等那么多调用端口中的接口
此外,代码可以抛出事件以供重用和隔离
,现在可以看到 vb6 类的骨架,
现在可以更仔细地查看 3 个方法
,即清理变量并准备环境,请参阅
内容
该方法具有
该方法的下一个职责内容
笔记:
该代码预期导致单个流而不是多个套接字响应
With mscomm control exists the same problem.
Work with async events always its harded.
First that is my personal way of deal with it
probably exist other way better. so it is one option more.
I've run into this problem more than one times and it often i forget how
deal with that. so that also be my personal reference
First the idea
well we need understand how the events happen
Graphic view that be the dead time, the dead time just is a time period
Now in vb6 when async events happen also need to happen two actions in different instant but are tested in the same moment
Also we will need some utility for keep track of time i used the win api GetTickCount
In mscomm also we will need add flag and string for know if some was received it for not wait so much in call to interface in the port
Also that code can throw event it for reuse and isolate
now see the skeleton of vb6 class
well now look at the 3 methods more closely
That clean variables and prepare the ambient, see the content
That method have the next responsibilities
content of the method
Note:
that code expected lead with a single stream not multiple socket responses