douxunnian0423 2016-09-01 05:39
浏览 1315

通过Websocket进行通信和发送大文件

I am buidling an App using Golang on server side and ReactNative/Node.js on client side.

A part of my app is to upload a video from the client to the server and to receive a video back (up to 100Mb).

As this is a bidirectionnal talk, I decided to use Websockets. This allow me to authenticate the user only once with its JWT Token and to keep the communication open up to the point where the client is uploading his video and receiving an other one in exchange.

Right now, I am at the point where I have to upload and download a video on both sides. All the communicatio has been in JSON so far. The video can be sent like this:

//After a few messages
{ "type": "sending_file", "sha2": `checksumofthevideo`}
{ "type":"video_chunk", "id": 1, data=`someverylongbytesofdata `}
{ "type":"video_chunk", "id": 2, data=`someverylongbytesofdata `}
{ "type":"video_chunk", "id": 3, data=`someverylongbytesofdata `}

The server, at the end, concatenates and writes all the bytes into a file then verify the checksum to make sure it is correct.

I am concerned about the effectiveness of this approach. I read that I should have used POST instead, allowing a much easier conversation and big files handling with the server.

Also Websockets are great for being used in a browser but in this case, I am using directly a node.js server on the client side so I guess this is lowering the advantage of the websocket.

I am having a really hard time to decide which one (REST vs Websocket) to use. I would appreciate any help about this, thanks!

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 请完成下列相关问题!
    • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
    • ¥15 求daily translation(DT)偏差订正方法的代码
    • ¥15 js调用html页面需要隐藏某个按钮
    • ¥15 ads仿真结果在圆图上是怎么读数的
    • ¥20 Cotex M3的调试和程序执行方式是什么样的?
    • ¥20 java项目连接sqlserver时报ssl相关错误
    • ¥15 一道python难题3
    • ¥15 牛顿斯科特系数表表示
    • ¥15 arduino 步进电机