VB.NET - Winsock GetData 方法
我在 vb.net 应用程序中导入了 Winsock 功能,这样我就可以制作一个聊天系统。我的程序只有一个小问题。在我的程序的 GetData 方法中,
客户端:
*Dim strData As String*
AxWinsock1.GetData(strData, vbString)
TextBox1.Text = TextBox1.Text & _
strData & vbCrLf
它将在整个第一行下划线,除非有一个 maxLen 作为对象。所以我插入了 Nothing,因为我认为它是可选的。现在,当我调试并从服务器发送消息时,它不会显示任何内容。我放入 vbByte 作为 maxLen 对象,现在它只显示部分消息。谁能告诉我如何解决这个问题。这适用于 VB6...
PS:我不会使用 VB.NET 的 System.Namespaces 函数,因为我发现 Winsock 功能更容易。
谢谢
I imported the Winsock feature in my vb.net application, so I can make a Chat System. I just have one little problem with my program. In the GetData method of my program,
CLIENT SIDE:
*Dim strData As String*
AxWinsock1.GetData(strData, vbString)
TextBox1.Text = TextBox1.Text & _
strData & vbCrLf
It will underline the whole first line, unless have an maxLen as Object in. So I plugged in Nothing, since I thought it was optional. Now when I debug, and I send a message from the server, it won't display anything. I put in vbByte as the maxLen object, and now it only shows part of the message. Can anyone tell me how to fix this. This works in VB6...
PS: I am not going to use the System.Namespaces function of VB.NET since, I find the Winsock feature much easier.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
vbByte 是一个值为 17 的常量,因此您实际上发送的最大长度为 17 ;-)
您将需要发送更大的数字作为最大长度。如果您要发送的最大长度是 Byte 数据类型的上限,您可以发送 Byte.MaxValue(即 255)。
编辑:
我不知道上限是什么,但你可以尝试
Integer.MaxValue
,或者一些任意大的值,比如1000000...看看文档,我注意到两件事:
maxLen应该是可选的,我不知道为什么当你不指定它时它会标记错误,它是什么样的错误?
有人提到,将 GetData 与 DataArrival 事件一起使用是很常见的,这是您的情况吗?如果是,您可以将
totalBytes
参数作为 maxLen 传递。vbByte is a constant with a value of 17, so you actually send a max length of 17 ;-)
You will want to send a bigger number as the max length. If what you want to send as a max length is the upper bound of the Byte data type you could send
Byte.MaxValue
(which is 255).Edit:
I don't know what is the upper bound, but you can try
Integer.MaxValue
, or some arbitrary big value like 1000000...Looking at the documentation, I noticed two things:
maxLen should be optional, I don't know why it would flag an error when you don't specify it, what kind of error is it?
It's mentioned that it's common to use GetData with a DataArrival event, is that your case? If it is, you could pass the
totalBytes
argument as the maxLen.