Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
211 views
in Technique[技术] by (71.8m points)

javascript - Flask Socket IO, Need help to understand why message grows in size

Hey Guys

What I do:

I stream live camera image data (jpeg encoded as binary) over flask socket-io to a client, socket message's has a frame and some meta data.

Each emitted message has around ~350KB in total.

When I stream one camera, the socket message's size on chrome devtools show's me the correct size.

Dev tools singel cam

When I stream multiple camera's socket messages are grow sometimes up to 3MB when I log the size on python side it is still around 350KB for each emitted message.

Dev tools multiple cameras

Can anybody explain me why this happen ? Thanks

Code:

This function send on python side the frame

@socket_io.on('frame_request')
def connect(data):
    while app.socket_online:
        frame = app.dm.get_frame_as_bytes(data["id"])
        emit('data',  {'meta': app.dm.get_meta_data(data["id"]), 'frame': frame})
        socket_io.sleep(1/12)

This function recive the incoming frames

handle_frame(frame) {
   var blob = new Blob([frame], {
       type: 'image/jpeg'
   });
   var url_create = window.URL || window.webkitURL;
   var imageUrl = url_create.createObjectURL(blob);
   this.img = imageUrl;
}
question from:https://stackoverflow.com/questions/65617329/flask-socket-io-need-help-to-understand-why-message-grows-in-size

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You are using the polling transport of Socket.IO. This transport can on certain situations when emits are sent at a high frequency combine multiple packets in a single polling response for efficiency.

If you enable WebSocket (which you should anyway, as it would give you much better performance) then each frame will be sent in its own individual packet.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...