Question details
Hello, did you try to use channels library? It will give you same powerful as Django-channels one. Here you can find necessary documentation for it.
I recommend you use it because it is give you more flexibility then Django-channels one.
Channels library
Quick start
You can read how to work with it at Tutorial.
Errors and solutions
Unexpected response code: 200 (or other code XXX) (solved):
- Be sure you include your application and channels via
settings (mysite.settings) and use asgi application:
INSTALLED_APPS = [
'channels',
'chat',
...
]
...
ASGI_APPLICATION = "mysite.asgi.application"
- Be sure you use channel layers (
mysite.settings).
CHANNEL_LAYERS = {
'default': {
'BACKEND': 'channels.layers.InMemoryChannelLayer',
},
}
According Documentation you should use database for production, but for local environment you may use channels.layers.InMemoryChannelLayer.
- Be sure you run
asgi server (not wsgi) because you need asynchronous behaviour. Also, for deployment you should use daphne instead of gunicorn. daphne is included in channels library by default, so you don't need to install it manually.
Basic run server will look like (Terminal):
daphne -b 0.0.0.0 -p $PORT mysite.asgi:application
where $PORT is specific port (for UNIX system is 5000). (That format used for heroku application, you can change it manually).
Error in connection establishment: net::ERR_SSL_PROTOCOL_ERROR and same errors with using https connection (solved):
Difference between ws and wss?
You may think about to use your server via wss protocol:
replace ws://... with wss://... or use following template in your html (chat/templates/chat/room.html):
(window.location.protocol === 'https:' ? 'wss' : 'ws') + '://'
Hope this answer is useful for channels with Django.