1

I have a Django project on Google Compute Engine. Here is the structure of my Django project.

example_channels
├── db.sqlite3
├── example
│   ├── admin.py
│   ├── apps.py
│   ├── consumers.py
│   ├── __init__.py
│   ├── migrations
│   │   
│   ├── models.py
│   ├── templates
│   │   └── example
│   │       ├── _base.html
│   │       └── user_list.html
│   ├── tests.py
│   ├── urls.py
│   └── views.py
├── example_channels
│   ├── asgi.py
│   ├── __init__.py
│   ├── routing.py
│   ├── settings.py
│   ├── urls.py
│   └── wsgi.py
└── manage.py

Following the tutorialsб I made an asgi.py:

import os
from channels.asgi import get_channel_layer

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "my_project.settings")

channel_layer = get_channel_layer()

I use asgi_redis as a back-end. The settings file looks like this:

CHANNEL_LAYERS = {
    'default': {
        'BACKEND': 'asgi_redis.RedisChannelLayer',
        'CONFIG': {
            'hosts': [('localhost', 6379)],
        },
        'ROUTING': 'example_channels.routing.channel_routing',
    }
}

I then try to start the server. I run python manage.py runworker & and get:

~/websockets_prototype/example_channels$ 2017-07-19 16:04:19,204 - INFO - runworker - Usi
ng single-threaded worker.
2017-07-19 16:04:19,204 - INFO - runworker - Running worker against channel layer default (asgi_redis.core.RedisCha
nnelLayer)
2017-07-19 16:04:19,205 - INFO - worker - Listening on channels http.request, websocket.connect, websocket.disconne
ct, websocket.receive

And then run Daphne:

~/websockets_prototype/example_channels$ 2017-07-19 16:05:28,619 INFO     Starting server
 at tcp:port=80:interface=0.0.0.0, channel layer example_channels.asgi:channel_layer.
2017-07-19 16:05:28,620 INFO     HTTP/2 support not enabled (install the http2 and tls Twisted extras)
2017-07-19 16:05:28,620 INFO     Using busy-loop synchronous mode on channel layer
2017-07-19 16:05:28,620 INFO     Listening on endpoint tcp:port=80:interface=0.0.0.0

I then start sending requests to the server, but I get This site can’t be reached error.

Ilya Lapan
  • 1,103
  • 2
  • 12
  • 31

1 Answers1

0

Try with daphne in port 8000 and reviews your ALLOWED_HOSTS=["*"] in settings.py

Juan Mite
  • 27
  • 1
  • 2