I've started the echo example from the distribution
https://github.com/sockjs/sockjs-node/tree/master/examples/echo
And I'm launching a websockets client at it. The client is attempting to
connect at /echo/websocket.
However, instead of the expected websocket handshake response, I get a
404 from the server and the server logs this out:
tim@Ethel:~/projects/sockjs-node/examples/echo$ node server.js
The "sys" module is now called "util". It should have a similar interface.
SockJS v0.3.1 bound to "/echo"
[*] Listening on localhost:8080
GET /echo/websocket 2ms (unfinished)
Any ideas?
Cheers
--
Tim Fox
Vert.x - effortless polyglot asynchronous application development
http://vertx.io
twitter:@timfox
From the command line:
$ cd sockjs-node
$ npm install --dev
$ make test_server
From the browser:
> ws = new WebSocket('ws://localhost:8081/echo/websocket');
> ws.onmessage = function(e){console.log('message', e.data)};
> ws.send('a')
message a
That works for me.
Marek
I'm not using a browser, I'm using a websockets client.
It's sending a GET request to /echo/websocket
> Marek
Hmm, I'm running from the echo example from the examples, as per the README
cd sockjs-node/examples/echo
npm install
node server.js
I tried to also run from sockjs-node dir as you suggested, but this
gives me an error:
tim@Ethel:~/projects/sockjs-node$ npm install --dev
tim@Ethel:~/projects/sockjs-node$ make test_server
node examples/test_server/server.js
node.js:201
throw e; // process.nextTick error, or 'error' event on first tick
^
Error: Cannot find module 'sockjs'
at Function._resolveFilename (module.js:334:11)
at Function._load (module.js:279:25)
at Module.require (module.js:357:17)
at require (module.js:368:17)
at Object.<anonymous>
(/home/tim/projects/sockjs-node/examples/test_server/sockjs_app.js:1:76)
at Module._compile (module.js:432:26)
at Object..js (module.js:450:10)
at Module.load (module.js:351:31)
at Function._load (module.js:310:12)
at Module.require (module.js:357:17)
make: *** [test_server] Error 1
> From the browser:
>> ws = new WebSocket('ws://localhost:8081/echo/websocket');
>> ws.onmessage = function(e){console.log('message', e.data)};
>> ws.send('a')
> message a
>
> That works for me.
>
> Marek
The only thing I can think of is perhaps the raw websocket transport is
not enabled on the sockjs-node server?
It's actually returning a 400 (not 404, my mistake), with status message
"Bad Request"
I grep'd through the sockjs-node source and can't find any "Bad Request"
so I guess this comes from the websockets library you use...
Tim,
You can't just issue a GET request, websockets handshake is more complicated.
You need more details, here's an example:
https://github.com/sockjs/sockjs-protocol/blob/master/sockjs-protocol-0.3.py#L604
Additionally, the raw websockets interface is intended to be used from
RFC6455 clients,
here's the relevant check:
https://github.com/sockjs/sockjs-node/blob/master/src/trans-websocket.coffee#L47
Cheers,
Marek
Yes, I was overoptimistic, you also need:
$ ln -s .. node_modules/sockjs
As suggested in sockjs-node readme.
Marek
Yes, obviously I understand that. (I have written a working websockets
client). :)
I am just telling you the GET request that the client is sending.
Anyway... I have got it working.
The problem seems to be in the versions of websockets that sockjs-node
understands.
Couldn't get it to work with Hybi00 or 08, but I can get it to work with
Hybi17 if I change the client to send the version 13.
This makes sense - I got it to work by sending the version number 13.
Can you explain a but why you only accept 8 and 13 as valid versions?
I'm not sure I really understand this
The original idea was to support only the 13, ie RFC6455, but
it was virtually impossible to test that - no python client supported
that. So I added '8' as a temporary measure.
I should revisit and remove the '8'.
Marek