[Fixed] multiple independent websockets connections

Issue

I have been playing around with django channels + angular. I have created an app that simply sends notifications to front end with a counter 1,2,3,4. It works fine, except if I open the page in multiple tabs. I am also not able to disconnect from the websocket, I can use unsubscribe but it does not really close the connection but that’s more kind of a angular question. Anyways how can I make my socket multithread, So if I make multiple requests from the same computer but from different tabs it will work and 2 different instances of the consumer will be created therefore, If I load 2 pages in the same computer the counter should be different independently increasing counter. Do I need redis for that ?

Solution

my url router was missing .as_asgi()
this worked:

URLRouter([path('wscrawpredict', CrawPredictConsume.as_asgi(),name="wscraw")])

Leave a Reply

(*) Required, Your email will not be published