Django and socket.io-client channels

I try to use them for the first time and be surprised that I headed in the right direction.

Here are my arrangements,

socket.io is a wrapper around websocket and returns to suboptimal solutions when websocket is unavailable.

Django channels can also talk to websocket.
(I think it converts django to a message queue as a system, although this understanding or misunderstanding should influence this question)

So, I am trying to use Django channels on the server and socket.io-client on the client.

socket.io has an api that looks like

socket.on(type, (payload)=> {})

While Django channels are shaped

message.reply_channel.send({ "text": json })

is the text type socket.on(type) ?

Can Django and socket.io-client channels talk to each other?

+11
django
source share
3 answers

From Socket.IO README:

Note. Socket.IO is not a WebSocket implementation. Although Socket.IO does use WebSocket as a transport when possible, it adds some metadata to each package: the type of package, namespace, and confirmation ID when message confirmation is required. This is why the WebSocket client cannot successfully connect to the Socket.IO server, and the Socket.IO client cannot connect to the WebSocket server (for example, ws: //echo.websocket.org). Please see protocol specification here .

Therefore, you should not expect channels to work directly with Socket.IO. Global browser support for web sockets is 93% , which is probably high enough to use the web socket API directly.

+5
source share

To quote the creator of Django feeds : https://github.com/django/channels/issues/1038

Channels do not support socket.io - this is another protocol that is not a web socket or HTTP, but layers on top of them. You will have to use the socket.io server if you want to use it.

0
source share

You can use django channels with socketio as a consumer and direct socketio traffic to socketio server. check it out https://github.com/ly3too/django-channels-with-socket.io

0
source share

All Articles