Answer the question
In order to leave comments, you need to log in
How to beat Channels(group chat app) please?
Good afternoon, people of the forum, help to deal with the problem.
I wrote a group chat using (Django 1.10 Channels 1.8 Daphne 1.4 Redis-server)
and, oddly enough, it turned out to be deployed the first time the chat worked, tested 10-11 people, everything was normal, they decided to open it for everyone here everything started and the chat went down and after that already stopped working :(
WebSocket connection to 'wss://example.com/dashboard/chat/' failed: WebSocket is closed before the connection is established
CHANNEL_LAYERS = {
"default": {
# This example app uses the Redis channel layer implementation asgi_redis
"BACKEND": "asgi_redis.RedisChannelLayer",
'CONFIG': {
"hosts": [os.environ.get('REDIS_URL', 'redis://localhost:6379')],
}
"ROUTING": "stp.routing.channel_routing", # We will create it in a moment
},
}
import os
import channels.asgi
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'stp.settings')
channel_layer = channels.asgi.get_channel_layer()
from channels import include
channel_routing = [
include('multichat.routing.chat_routing', path=r"^/dashboard/chat/"),
]
from channels.routing import route
from multichat.consumers import *
chat_routing = [
route("websocket.connect", chat_connect),
route("websocket.receive", chat_receive),
route("websocket.disconnect", chat_disconnect)
]
@channel_session_user_from_http
def chat_connect(message):
logger.info('websocket_connect. message = %s', message)
Group("all").add(message.reply_channel)
Room.objects.add("all", message.reply_channel.name, message.user)
message.reply_channel.send({"accept": True})
location /dashboard/chat/ {
proxy_pass http://0.0.0.0:8001;
proxy_http_version 1.1;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
./manage.py runworker --traceback
2018-03-06 18:28:10,456 - INFO - runworker - Using single-threaded worker.
2018-03-06 18:28:10,456 - INFO - runworker - Running worker against channel layer default (asgi_redis.core.RedisChannelLayer)
2018-03-06 18:28:10,457 - INFO - worker - Listening on channels http.request, websocket.connect, websocket.disconnect, websocket.receive
daphne -b 0.0.0.0 -p 8001 stp.asgi:channel_layer
2018-03-06 18:29:57,498 INFO Starting server at tcp:port=8001:interface=0.0.0.0, channel layer stp.asgi:channel_layer.
2018-03-06 18:29:57,499 INFO HTTP/2 support not enabled (install the http2 and tls Twisted extras)
2018-03-06 18:29:57,499 INFO Using busy-loop synchronous mode on channel layer
2018-03-06 18:29:57,499 INFO Listening on endpoint tcp:port=8001:interface=0.0.0.0
127.0.0.1:55384 - - [06/Mar/2018:18:30:23] "WSCONNECTING /dashboard/chat/" - -
127.0.0.1:55384 - - [06/Mar/2018:18:30:25] "WSDISCONNECT /dashboard/chat/" - -
127.0.0.1:55478 - - [06/Mar/2018:18:30:55] "WSCONNECTING /dashboard/chat/" - -
127.0.0.1:55478 - - [06/Mar/2018:18:30:57] "WSDISCONNECT /dashboard/chat/" - -
127.0.0.1:56066 - - [06/Mar/2018:18:31:27] "WSCONNECTING /dashboard/chat/" - -
127.0.0.1:56066 - - [06/Mar/2018:18:31:29] "WSDISCONNECT /dashboard/chat/" - -
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question