.Net Framework 中的 TCP ReceiveBufferSize 最大大小
我正在尝试使用 System.Net.Sockets 内的 TCP/Sockets 函数来传输文件。 但是,当我尝试动态设置客户端和服务器上的缓冲区大小(如果大小小于 4096)时,传输效果很好,但如果大于 4096,缓冲区将保留 4096 值,因此文件是没有完全收到。
所以,我想知道?这是最大值吗? 如果是,使用客户端上循环充满并在服务器上以相同方法接收的缓冲区是否安全?
感谢您的帮助。
I'm trying to use the TCP/Sockets function inside System.Net.Sockets to transfer files.
But, when I try to dynamicaly set the size of the buffer on the client and on the server if the size is less that 4096, the transfert done well but if it's more than 4096, the buffer keep the 4096 value and so the file is not received completly.
So, I was wondering ? Is this the maximum value ?
If yes, Is it safe to use a Buffer which is fulled by a loop on the client and received with the same method on the server ?
Thanks for help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我曾经编写过一个类似且非常简单的带有套接字的文件接收器(只是为了尝试套接字,所以代码不是那么漂亮):
发送器代码如下所示:
I've written a similar and very simple file receiver with sockets once (just to try sockets, so the code isn't all that pretty):
The sender code looked like this:
如果您尝试发送较大的文件,.net 通常会将它们分成较小的块。您需要在客户端接收到数据时,逐段重新组装数据。我认为 networkComms.net 中的 ConnectionPacketBuilder 类,第 134 行 这里实现了您想要做的事情。您可以看到它是如何使用的,因为数据出现在第 793 行左右。
If you are trying to send larger files .net commonly breaks them up into smaller chunks. You need to reassemble the data as it is received, piece by piece, at the client end. I think the ConnectionPacketBuilder class in networkComms.net, line 134 here achieves what you want to do. You can see how it is used as data comes in around line 793.