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 怎么让wx群机器人发送音乐
    • ¥15 fesafe材料库问题
    • ¥35 beats蓝牙耳机怎么查看日志
    • ¥15 Fluent齿轮搅油
    • ¥15 八爪鱼爬数据为什么自己停了
    • ¥15 交替优化波束形成和ris反射角使保密速率最大化
    • ¥15 树莓派与pix飞控通信
    • ¥15 自动转发微信群信息到另外一个微信群
    • ¥15 outlook无法配置成功
    • ¥30 这是哪个作者做的宝宝起名网站