views:

106

answers:

1
+1  A: 

OK there a couple of things wrong here, the reason why only the onclose handle is fired is because the browser does not receive a valid handshake and therefore terminates the connection.

  1. You always send ws://127.0.0.1:8124/ as the location, the location should exactly match whatever the browser send in the request in this case it would be most likely localhost:8124 so you should return ws://localhost:8124/ in such a case.

  2. You're missing another \r\n after the response headers, so you're in fact not sending any body.

  3. There seems to be something wrong with your calculation of the hash value, I'm still trying to figure out what though(cough code isn't that readable after all cough)

For a working(and pretty small) implementation see here:
http://github.com/BonsaiDen/NodeGame-Shooter/blob/master/server/ws.js

Ivo Wetzel
#3 was spot on. My spaces calculation was incorrect. Thanks for the help and the link.