How can I transfer bytes in chunks to clients?

情到浓时终转凉″ 提交于 2020-01-02 03:55:07

问题


SignalR loses many messages when I transfer chunks of bytes from client over server to client (or client to server; or server to client).

I read the file into a stream and sent it over a hub or persistent connection to other client. This runs very fast, but there are always messages dropped or lost.

How can I transfer large files (in chunks or not) from client to client without losing messages?


回答1:


As @dfowler points out, it's not the right technology for the job. What I would recommend doing is sending a message that there is a file to be downloaded that includes the link and then you can download that file using standard GET requests against either static files or some web service written with ASP.NET WebAPI.




回答2:


SignalR isn't for file transfer, it's for sending messages.




回答3:


Why isn't it the right technology? If a client needs to send some data to a signalR hub it should be able to over the signalR connection without requiring additional stuff.

In fact it works fine when sending a byte array, at least for me, however I encountered similar problems when transferring chunks.

Perhaps you can do some tests to check if the order in which you send the chunks is the same as the order they are received.

UPDATE

I did a test myself and in my case the order was indeed the problem. Modified the hub method receiving the chunks to accept an order parameter which I then use to reconstruct the byte array at the end and it works fine. Having said this I however now understand that this wouldn't work well with large file transfers.

In my case I don't need to transfer very large amounts of data, I just wanted to give my UI an indication of progress, requiring the data to be sent in chunks.



来源:https://stackoverflow.com/questions/12824783/how-can-i-transfer-bytes-in-chunks-to-clients

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!