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.
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 likelylocalhost:8124
so you should returnws://localhost:8124/
in such a case.You're missing another
\r\n
after the response headers, so you're in fact not sending any body.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