从ClientSocket读取NetworkStream.Read接收数据时出错 [英] Error receiving data with NetworkStream.Read from a ClientSocket

查看:424
本文介绍了从ClientSocket读取NetworkStream.Read接收数据时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

当我收到从一个应用程序发送到另一应用程序的数据时,出现错误.一个应用程序充当服务器,并将数据发送到通过特定端口连接到服务器的客户端.
我通过clientocket发送了一些信息,当时我收到了此错误.

Hi guys,

When I receive data sent from one application to another application I get an error. One application acts as the server and sends data to the client that connected to the server on a particular port.
I sent some information via clientsocket and at that time I got this error.

"Specified argument was out of the range of valid values.Parameter name: size"


这是我的编码...


Here my coding ...

Dim bytesFrom(10024) As Byte

networkStream.Read(bytesFrom, 0, CInt(clientSocket.ReceiveBufferSize))



clientSocket.ReceiveBufferSize为505196.

我不明白这个问题.有人可以帮忙吗?


问候,

Saran.t



clientSocket.ReceiveBufferSize is 505196.

I don''t understand this problem. Can anyone help please?


Regards,

Saran.t

推荐答案

问题在于调用函数Read时的参数CInt(clientSocket.ReceiveBufferSize. 除此之外,为什么还要将505196字节读取到只能占用10024字节的数组中,这是一个错字,并且您想说的是bytesFrom缓冲区甚至只有1024个字节.

说明:

如果缓冲区的大小小于NetworkStream.Read函数的大小参数,则会引发ArgumentOutOfRange异常.

请参阅此处: http://msdn.microsoft.com/en-us /library/system.net.sockets.networkstream.read.aspx [
The problem is with the argument CInt(clientSocket.ReceiveBufferSize in invocation of function Read.
Besides that why would you want to read 505196 bytes into an array that can only take 10024 bytes, is this a typo and you wanted to say your bytesFrom buffer was even only 1024 bytes.

Explanation:

If the size of buffer is less than the size parameter of NetworkStream.Read function an ArgumentOutOfRange Exception is thrown.

See here: http://msdn.microsoft.com/en-us/library/system.net.sockets.networkstream.read.aspx[]

Please make the amount of bytes you want to read smaller or equal to the size of your buffer.


Cheers,


Manfred


这篇关于从ClientSocket读取NetworkStream.Read接收数据时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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