ger.s.brett
ger.s.brett

Reputation: 3308

django channels websocket connect not working

I am trying to run the multichat project from django channels-examples on a server. It works locally on a windows machine but when I put this on the linux server and start it with runserver it does not:

./manage.py runserver

Then when I call up the website, it is shown correctly but as soon as the JS sends it websocket request I always get this reponse:

[2016/08/02 14:35:48] HTTP GET /chat/stream/ 404 [0.04, 127.0.0.1:40186]
....(many lines of this)

So the websocket request is handled as an http request. The response should be this:

[2016/08/02 16:34:45] WebSocket CONNECT /chat/stream/ [127.0.0.1:60250]

I have no clue where this is going wrong. The routing of http versus websocket seems to be done somewhere deep inside daphne/twisted/...

My channel settings are (if that is of any help at all):

CHANNEL_LAYERS = {
    "default": {
        "BACKEND": "asgi_redis.RedisChannelLayer",
        "CONFIG": {
            "hosts": [(redis_host, 62031)],
        },
        "ROUTING": "multichat.routing.channel_routing",
    },
}

Twisted version is 16.2.0.

Any help or hint in what direction to look is very appreciated.

Upvotes: 3

Views: 4028

Answers (2)

ahumblenerd
ahumblenerd

Reputation: 225

Can you post the complete log ?

Try running the server with daphne and run worker

daphne multichat.asgi:channel_layer --port 80 --bind 0.0.0.0 -v2 
python manage.py runworker -v2 

Use something like supervisor to do this in a better way to restart these on failure.

Upvotes: 1

DA--
DA--

Reputation: 765

Some questions/suggestions that come to mind:

Is the linux server for development or production? I.e. Is there a HTTP server or just plain DJANGO running? (In the former case you don't start with "./manage runserver".)

"Then when I call up the website, it is shown correctly ..."

Is this because the port numbers different for the the requests? 40186 vs 60250.

You're getting a 404, e.g. url Not Found. This can be either the response of the HTTP server of from DJANGO.

Upvotes: 1

Related Questions