Skip to content
This repository

Messages from client to WebSocket are not working #35

Closed
VanCoding opened this Issue · 14 comments

5 participants

Patrik Stutz Charlie Robbins Elad Ben-Israel ironchefpython
Patrik Stutz

I have a problem with proxying messages from the client to the websocket server.
The messages do not reach the websocket server at all. When I connect to the server directly, it works.

However, all other things work. I can conenct & send messages to the client.

I´m using the following websocket server: https://github.com/miksago/node-websocket-server

Has anyone the same problem?

Marak commented

Hrmm, the current test suite has coverage for socket.io and it appears to be passing.

Can you please confirm the results of this test first?

 vows test/web-socket-proxy-test.js --spec

If those tests all pass, then there might be an issue with http-proxy and node-websocket-server.

Patrik Stutz

I found the problem:
When proxying messages, the incoming data is a bit different:

WITHOUT proxying
Buffer 00 68 65 6c 6c 6f 20 77 6f 72 6c 64 ff
Buffer 00 68 65 6c 6c 6f 20 77 6f 72 6c 64 ff

WITH proxying
Buffer 00 68 65 6c 6c 6f 20 77 6f 72 6c 64 ef bf bd
Buffer 00 68 65 6c 6c 6f 20 77 6f 72 6c 64 ef bf bd

The messages are not well cut anymore. Hope this helps.

Patrik Stutz

I fixed the problem for me by always doing "socket.setKeepAlive(true, 0);" in the _socket function and never set the encoding to utf8.

It seems that was the only problem. Now I get the same data from both ways.

Marak commented

Would you be willing to put a pull request together?

Patrik Stutz

I´m not sure if my changes are good for all users of this library. I know it works for me like a charm now, but maybe the deleted lines of code were good for someone else.

Charlie Robbins
Owner

This should be resolved in v0.5.3

Charlie Robbins indexzero closed this
Elad Ben-Israel
eladb commented

Hi, I'm running with v0.5.11 and this issue still exists there.
It seems that the problem is that the client socket has utf-8 encoding set. Once removed, everything works perfectly:

function _socket(socket, keepAlive) {
    socket.setTimeout(0);
    socket.setNoDelay(true);
    if (keepAlive) {
      if (socket.setKeepAlive) {
        socket.setKeepAlive(true, 0);
      }
      else if (socket.pair.cleartext.socket.setKeepAlive) {
        socket.pair.cleartext.socket.setKeepAlive(true, 0);
      }
    } 
    else {
      //socket.setEncoding('utf8');
    }
}

Let me know if you want me to set up a pull request.

Charlie Robbins
Owner

@eladb What messages are you trying to proxy that are not getting through? We have extensive test coverage for websockets that are all passing

I think the correct approach here would be to make the encoding of the data being sent across the websocket configurable.

Can you please provide a full code sample that reproduces the issue?

Elad Ben-Israel
eladb commented
Elad Ben-Israel
eladb commented
Charlie Robbins
Owner

@eladb I might be missing something but where can I find test.js and test-patched.js?? Will try later this evening.

Elad Ben-Israel
eladb commented
ironchefpython

@eladb Can you provide a link to the zip file?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.