如何处理NetworkStream.BeginRead [英] How to handle NetworkStream.BeginRead

查看:95
本文介绍了如何处理NetworkStream.BeginRead的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我了解到TCP可以确保数据包到达的顺序,但不能确保它们是完整的.
我还读到解决此问题的系统是先发送数据包大小,然后读取直到收到完整的程序包,但我不知道如何实现这样的系统.

I read that TCP ensures the order of arrival of packets, but does not ensure that they are complete.
I also read that a system to solve this problem would be to first send the packet size and then read up until receiving a full package, but I do not understand how to implement such a system.

推荐答案

您必须了解的是,TCP就像一个管道,可以在其中传输数据.最重要的是,您可以实现自己喜欢的协议或消息系统.

说说您要发送和接收的文件.然后,您必须告诉接收者有关您将发送的文件的一些信息.它可以是文件名,创建日期/时间和文件大小.
当接收者知道该信息时,它将知道如何解释接收到的数据.

查看 HTTP协议 [ ^ ].它已经使用了很多年.
You have to thing about that TCP is like a pipe where data can be transported in. On top of that, you can implement what ever protocol or message system you like.

Say you what to send and receive a file. Then you have to tell the receiver some information about that file you will sent. It can be file name, create date/time and the size of the file.
When the receiver knows about that info, it will know how to interpret the data received.

See how HTTP protocol[^] is built up. Its been used for many years now.


请查看我在过去的解决方案中展示的框架设计:
来自同一端口号的多个客户端 [
Please see the skeleton design I show in my past solution:
Multple clients from same port Number[^].

—SA


这篇关于如何处理NetworkStream.BeginRead的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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