简体   繁体   English

发送大量的TCP数据

[英]sending massive amounts of TCP data

So im working with C#, and i have to send lots and lots of data every time a client makes an initial connection.. I would prefer to have some way to track the progress of the message, and one way i thought to do that would be to split my large amount of data into 500 or more smaller portions, and send them individually. 因此,我正在使用C#,并且每次客户端建立初始连接时,我都必须发送大量数据。.我希望有某种方法来跟踪消息的进度,而我认为这样做的一种方法是将我的大量数据分成500个或更小的部分,然后分别发送。 Would that be an acceptable practice? 这是可以接受的做法吗? or is it better to send one gigantic message. 还是发送一条巨大的消息更好。

What I do when sending large amounts of data is send it in 100 pieces each being more than 50kb and then update a progress bar by whatever the current percentage is. 发送大量数据时,我要做的是将其发送为100条,每条超过50kb,然后根据当前百分比更新进度条。 I do it by serializing the file to a byte[] and then in a while loop, send then Application.DoEvents() to update the UI. 我将文件序列化为byte [],然后在while循环中发送,然后发送Application.DoEvents()来更新UI。

I'm sure you could use Async background workers as well and then have the Update event increment the progress bar. 我确定您也可以使用异步后台工作程序,然后让Update事件增加进度条。

I would say, if you can split it up, do it. 我会说,如果您可以将其拆分,那就去做。 Because if there is an interruption in the connection you can always restart etc. That's why bittorrent and the ilk divide file into chunks. 因为如果连接中断,您可以随时重启等。这就是为什么bittorrent和ilk将文件分成多个块的原因。

Just make sure that you have good checksums and error detection. 只要确保您具有良好的校验和和错误检测。 The more pieces you split, the more pieces you have to keep track of. 您分割的片段越多,就需要跟踪的片段越多。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM