Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiplexing channels in a websocket

I'm developing an application where I need real-time communication and file upload. I'd preferably like to do it over a single connection with multiplexed channels. I see there is a an extension to the websocket protocol to allow multiplexing but I don't think there is yet browser support, if there is.. I have no idea how to use it.

I'm wanting to develop the server in java. The node server for socketio had a weird bug with namespaces and the java server for it didn't work correctly with namespaces.

I want a simple multiplexing system so that I can send some json and binary at the same time. Is there something existing for this or do I need to create something myself, if so.. where do I start?

like image 620
B3NW Avatar asked Jul 20 '15 12:07

B3NW


2 Answers

One thing i want to point out is Multiplexing is not about supporting multiple message formats, since webSocket doesn't specify the body format, so it's similar to HTTP, you can send JSON, picture, binary... anything you want.

Multiplexing is about how to re-use one connection channel to support multiple communications (similar concept in telecommunications), this is usually being used in scenario where multiple modules need websocket communication, but only one connection is allowed (like SocketJS), then we can employ Multiplexing tech to save the world.

More information please see: https://github.com/sockjs/websocket-multiplex https://www.rabbitmq.com/blog/2012/02/23/how-to-compose-apps-using-websockets/

like image 101
Frank Zhang Avatar answered Oct 17 '22 02:10

Frank Zhang


There are pre-made Javascript libraries for the client side, including this one: WebSocketFileTransfer.

As for Server side solutions, I'm less in the know. I would probably opt for two websocket connections or for dividing the file into smaller websocket messages using the HTML5 javascript - this would allow psedo-multiplexing through the fact that it's possible to send different websocket messages between file-chunks.

I prefer Ruby and I would probably write my app (or, at least the websocket backend) using the Plezi framework... but I'm not sure if the namespace issue you mentioned would still bother you if you decide to pseudo-multiplex by dividing the file into chunks.

EDIT

I just had a thought, that unless you divide the file sent into smaller chunks that are later reassembled, it would be very hard to give feedback regarding the upload process ...

Your websocket server (unless you're writing your own) won't let you know about incoming data until the file transfer is complete, so you couldn't update the client about how much was received. Also, dividing the file might let you reinitiate uploads if the connection is dropped.

Thinking of this, I would opt for a single connection and dividing each file to number of chunks (perhaps a chunk for every 100Kb or so, depending on your server and intended use).

like image 43
Myst Avatar answered Oct 17 '22 04:10

Myst