Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
pkkid opened this issue Feb 9, 2016 · 2 comments
Closed

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

pkkid opened this issue Feb 9, 2016 · 2 comments

Comments

@pkkid
Copy link

pkkid commented Feb 9, 2016

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:

  • Do I need to kickstart a websocket facility by calling it from Python land by publishing an initial message? ..or can any javascript client start a new facility by simply calling some url like ws://domain/<new-facility>?.... If the latter, does this open the door to a DOS attack on the Redis server by some rouge user making millions of facilities?
  • Is there additional logging I am missing somewhere to help debug whats going on the websocket loop? I was getting an exception that took me forever to find because I'm running Python3 and the current gevent lib doesn't support it yet (but their release candidate does). However, I didn't see that exception bubble up anywhere.
@jrief
Copy link
Owner

jrief commented Feb 9, 2016

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

When fixed, please close this issue.

@pkkid
Copy link
Author

pkkid commented Feb 10, 2016

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.

@pkkid pkkid closed this as completed Feb 10, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants