socketio send message from server(django-socketio)

485 views Asked by At

I use django-socketio library.

In some view, i want send message for all clients. But when i use the follow code:

from django_socketio import broadcast

def some_view(request):
    data = {"message": "Some message"}
    broadcast(data)
    return HttpResponse('Ok')

i get an error:

There are no clients.

But if send broadcast from event, all alright.

from django_socketio.events import on_message, on_subscribe

@on_subscribe(channel='machine')
def machine_cash_handler(request, socket, context, message):
    broadcast(data)
0

There are 0 answers