jrief / django-websocket-redis

Websockets for Django applications using Redis as message queue
http://django-websocket-redis.awesto.com/
MIT License
895 stars 222 forks source link

Error during WebSocket handshake: Unexpected response code: 404 #165

Closed pkkid closed 8 years ago

pkkid commented 8 years ago

After playing with this app, I've been having quite a bit of trouble just getting a simple connection going. I believe I followed all the instructions, but something still isn't right. Everything posted below is being run through the django-admin runserver command.

1.) The error I'm getting is in the browser is:

ws4redis.js:20 WebSocket connection to 'ws://localhost:8000/ws/foobar?subscribe-broadcast'
failed: Error during WebSocket handshake: Unexpected response code: 404
ws4redis.js:69 Websocket connection is broken! on_error @ ws4redis.js:69
Connection closed!

2.) And I see this in the runserver output:

"GET /ws/foobar?subscribe-broadcast HTTP/1.1" 404 3366

3.) The javascript code I'm trying to use to connect is the following:

pk.magnets = {
  init: function(selector, opts) {
    this.container = $(selector);
    this.ws = this.init_websocket();
  },

  init_websocket: function() {
    return new WS4Redis({
        uri: 'ws://localhost:8000/ws/foobar?subscribe-broadcast',
        receive_message: this.receive_message,
        connected: this.on_connected,
        heartbeat_msg: '--heartbeat--',
    });
  },

  send_message: function() {
    this.ws.send_message('A message');
  },

  receive_message: function() {
    console.log('receive_message');
    this.ws.send_message('Hello');
  },

  on_connected: function() {
    console.log('on_connected');
  },
};

4.) I have no Python (server-side) code handing the websockets yet, but I was running the short snippet in the docs to broadcast a message thinking I may have to start a new facility from there or something.

Finally, I have some questions that the documentation didn't quite make clear to me:

jrief commented 8 years ago

well, error 404 normally means that the endpoint wasn't found. This is certainly a configuration error.

When fixed, please close this issue.

pkkid commented 8 years ago

Looking at the docs with rest and fresh eyes, it was easy to spot the error. I was missing all the required settings under the Note: Specify only the values, which deviate from the default thinking they were not required.