VB6 异步 Tcp 客户端截断传入消息 [英] VB6 Asynchronous Tcp Client truncates incoming messages

查看:72
本文介绍了VB6 异步 Tcp 客户端截断传入消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 C# Tcp 服务器,它向注册的 VB6 Tcp 客户端发送消息.消息的接收是使用 WinSock 以异步方式完成的.因此,已完成"消息出现的 VB6 部分如下所示:

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

问题是 C# Tcp 服务器正在发送一个长度为 6874 的字符串,但是当我们检查 DataArrival 事件触发时收到的消息大小时,它的测量值只有 2920.很明显,传入消息的这种截断是一个严重的问题.

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.

以前有人观察过吗?

推荐答案

正如我在这里所说的 VB6 WinSock TCP 客户端和 .NET TCP 服务器:

As I said here VB6 WinSock TCP client and .NET TCP server:

这是一个常见的误解,认为您正在接收消息.你正在接收字节流.sBuff 可能包含 1 个字节,它可能包含构成您的信息的 50%,通常(如果它们很小足够)它可以包含 100% 的信息,有时它可以包含超过 100%(意味着它包含下一条消息的某些部分).没有看到 ProcessMessage 中的代码,我不能确定你有问题,但您应该确保该方法可以处理所有这些场景

That is a common misconception, that you are receiving messages. You are receiving a stream of bytes. sBuff may contain 1 byte, it may contain 50% of what makes up your message, often (if they are small enough) it can conatin 100% of your message, and sometimes it can contain more than 100% (meaning it has some part of the next message). Without seeing the code in ProcessMessage I cannot be sure you have a problem, but you should make sure that method can handle all of these scenarios

仅仅因为您在 DataArrival 上只看到 2920 的数据长度并不意味着数据被截断.这只是意味着那是当时可用的全部.将该数据读入缓冲区,然后当您发送的下一部分数据可用时,该事件将再次触发.继续读取可用数据并附加到您的缓冲区,直到您获得完整的消息.

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.

这篇关于VB6 异步 Tcp 客户端截断传入消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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