2

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)
Arti
  • 7,356
  • 12
  • 57
  • 122
  • A view is based by definition on an Http request/response cycle. broadcast() requires a socket to work, and the view itself does not create the socket, that happens after the view has already served the response and the js in your template calls io.connect(). What are you actually trying to accomplish, maybe I can help with that. – Isaac Ray Nov 01 '14 at 15:51
  • I have a similar issue. I have created the namespace where I keep track of the sockets. I process something in the background, and when that's finished I need to send notifications. – bogs Jan 03 '15 at 16:14

0 Answers0