Closed drasko closed 9 years ago
thanks for reporting. strange, the code is used on daily basis... how did you install it?
I installed it via luarocks. I just said:
sudo luarocks install lua-websockets
I installed luarocks via apt-get.
Reinstalled now from git - built with
luarocks make rockspecs/lua-websockets-scm-1.rockspec
following the instructions.
Still same thing - "bad protocol"
How can I debug?
could you try to add the 'echo' protocol, please:
ws = new WebSocket("ws://" + host + ":" + port + uri, "echo");
i just tried to connect from browser to the "echo-server-copas.lua" manually and it worked fine. (besides the automated tests are passing).
you could debug with a "real" debugger (like zerobrane studio) or by adding prints to the sources. the interesting spot should be "server_copas.lua" lines 100 to 111 (this is where the "bad protocol" error is generated.
ahhh... i just compared the README.md echo server example and there is no default protocol specified, that means that u MUST define the protocol:
ws = new WebSocket(..., "echo");
the second param the the websocket ctor ("echo") is the important thing here!
Yes, indeed! Thanks, it is working now.
But why are we obliged to define the protocol like this? Can you please elaborate on this, it would be very helpful!
I have been used this JavaScript code before with other WebSocket servers (like Tornado, etc..), and I have never defined protocol before.
you can define a "default" handler, which will be chosen if no protocol has been provided by the client:
https://github.com/lipp/lua-websockets/blob/master/API.md#configdefault
the copas echo server (https://github.com/lipp/lua-websockets/blob/master/examples/echo-server-copas.lua) does both, as it provides a "explicit" echo protocol handler and a "default" handler (which - in this case- is the same.
@drasko is http://we-io.net/index.html your project? maybe this could be of use for you: http://jetbus.io
I tried with several WebSocket clients and I am constantly getting "bad protocol" error.
Is the code functional?
I am using an example "copas echo server" with freshly installed lua5.1 on Debian Linux:
I tried test with both this code from the browser (both Chrome and Firefox):
And also this code from Python: https://github.com/liris/websocket-client
Same result - "bad protocol".
Best regards, Drasko