django-channels

Django channels websocket reconnect

馋奶兔 提交于 2021-01-29 20:15:53
问题 I am building a messaging system in Django, using web-socket to receive the message. Here is my tryouts, from channels.consumer import AsyncConsumer from channels.db import database_sync_to_async class ChatConsumer(AsyncConsumer): async def websocket_connect(self, event): print("connected", event) await self.send({ "type": "websocket.accept" }) async def websocket_receive(self, event): print("receive", event) message = event['text'] obj = await self.create_obj(message=message) print('Created.

Django channels websocket reconnect

五迷三道 提交于 2021-01-29 16:11:48
问题 I am building a messaging system in Django, using web-socket to receive the message. Here is my tryouts, from channels.consumer import AsyncConsumer from channels.db import database_sync_to_async class ChatConsumer(AsyncConsumer): async def websocket_connect(self, event): print("connected", event) await self.send({ "type": "websocket.accept" }) async def websocket_receive(self, event): print("receive", event) message = event['text'] obj = await self.create_obj(message=message) print('Created.

I want to use aioredis connection pool ,not create new connection in every AsyncWebsocketConsumer.connect .Where can I put the code

流过昼夜 提交于 2021-01-29 05:50:55
问题 I want to use aioredis connection pool ,not create new connection in every AsyncWebsocketConsumer.connect .Where can I put the code. Now I create new connection in connect event every time, code like this async def connect(self): self.redis = await aioredis.create_redis( 'redis://localhost',encoding='utf-8') async def disconnect(self, close_code): await self.redis.close() I need something like self.channel_layer ,using pool connection across every consumer. Thanks. 回答1: Probably not the best

Using Django Channels for a progress indicator

ⅰ亾dé卋堺 提交于 2021-01-28 06:01:18
问题 I have a django app that carries out some calculations on the server which can take up to 30 seconds. I am trying to use django channels to create a progress indicator. My setup is based on this tutorial: https://realpython.com/blog/python/getting-started-with-django-channels/ Everything is working as expected so far. I submit a task by web socket. This is received by my consumer, which calls other methods to complete the task, then returns the result by websocket. However, when I try to send

Django channels with Spring Boot Websockets (StompSession) do not work

邮差的信 提交于 2021-01-22 00:52:16
问题 Hey there we want to use Django just to execute python code and use channels for the results. Implemented everything the websockets are not working as they should. If I try to send something from our Angular frontend to Django it works fine. And otherwise our Spring Boot StompSession Websockets work fine with other Spring Boot Applications and Angular. But Django 3.1.3 and Spring Boot 2.3.3 do not. Additionally channels 3.0.2, channels-redis 3.2.0 and a docker container of redis 6 are used.

How to create task which sends data continuously and disconnect safely in consumers, django channels 2?

蓝咒 提交于 2021-01-01 07:03:41
问题 From this answer, which helps to send data from consumers for every n seconds. Tried to handle the disconnection properly, using creat_task method, tried to stop while-loop (which is used to send data for every n seconds) by sending a flag=False (Assuming, this flag is not sent to the same instance which is created the task). consumers.py: class AutoUpdateConsumer(AsyncConsumer): async def websocket_connect(self, event): print("connected", event) await self.send({ "type": "websocket.accept" }

How to create task which sends data continuously and disconnect safely in consumers, django channels 2?

孤者浪人 提交于 2021-01-01 07:02:41
问题 From this answer, which helps to send data from consumers for every n seconds. Tried to handle the disconnection properly, using creat_task method, tried to stop while-loop (which is used to send data for every n seconds) by sending a flag=False (Assuming, this flag is not sent to the same instance which is created the task). consumers.py: class AutoUpdateConsumer(AsyncConsumer): async def websocket_connect(self, event): print("connected", event) await self.send({ "type": "websocket.accept" }

WebSocket disconnect received unexpectedly by using Django Channels

╄→尐↘猪︶ㄣ 提交于 2020-12-13 07:16:55
问题 Using Django channels to update the user on the current status of a potentially long running task, I'm facing a WebSocket DISCONNECT that I would like to trace down. The setup looks pretty straight forward. settings.py defines the channel layer: ASGI_APPLICATION = "config.routing.application" CHANNEL_LAYERS = { 'default': { 'BACKEND': 'channels_redis.core.RedisChannelLayer', 'CONFIG': { "hosts": [('127.0.0.1', 6379)], }, }, } In routing.py we basically follow the default suggestion from the

WebSocket disconnect received unexpectedly by using Django Channels

跟風遠走 提交于 2020-12-13 07:15:59
问题 Using Django channels to update the user on the current status of a potentially long running task, I'm facing a WebSocket DISCONNECT that I would like to trace down. The setup looks pretty straight forward. settings.py defines the channel layer: ASGI_APPLICATION = "config.routing.application" CHANNEL_LAYERS = { 'default': { 'BACKEND': 'channels_redis.core.RedisChannelLayer', 'CONFIG': { "hosts": [('127.0.0.1', 6379)], }, }, } In routing.py we basically follow the default suggestion from the

Django Websockets Data going to the wrong Socket

↘锁芯ラ 提交于 2020-12-10 09:14:35
问题 Using Django Websockets + Channels, I create a (One) group and the message back and forth works just fine. Lets call this Group A The problem starts when I open a SECOND group and a SECOND (Lets call this group B) WebSocket connection in a different browser. The messages that I am trying to send to group A (first WebSocket connection), are going to group B (second WebSocket connection). All the messages that belong to group A go to the second WebSocket and the group B messages also go to the