Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Server] ws.remoteAddress unexpected value #3

Closed
Turbine1991 opened this issue May 19, 2020 · 4 comments
Closed

[Server] ws.remoteAddress unexpected value #3

Turbine1991 opened this issue May 19, 2020 · 4 comments
Labels
bug Something isn't working

Comments

@Turbine1991
Copy link

Turbine1991 commented May 19, 2020

I'm running a simple server based on the examples:

    const fastWS = require('fast-ws/server');

    const options = {};
    const app = new fastWS(options)

    app.ws('/db', ws => {
      console.log(`Connected ${ws.remoteAddress}`)

      ws.on('message', ({ data }) => {
        console.log(`Received: ${data}`);
        ws.sendMessage(data)
      })

      ws.on('echo', ({ reply, data }) => {
        reply(data)
      })
    });

    const [host, port] = ['127.0.0.1', 8080];
    app.listen(host, port, () => {
      console.log(`Listen on ${host}:${port}`)
    })

Unfortunately, when I connect using the code below:

  const Client = require('fast-ws/client')

  const options = {
    // Ping Interval (not less then server `idleTimeout`)
    pingInterval: 30000, // Default (ms)
    // Reply Timeout (Event reply)
    replyTimeout: 5000, // Default (ms)
    // parser options (same as server)
    parserOptions: {},
    // Others options for package 'ws'
  };
  
  const ws = new Client('ws://127.0.0.1:8080/db', options)

I get this output upon connection:
Connected 7f00:0001:

IPv6 is disabled, so I have no idea what this value actually is.

Cheers.

@Turbine1991
Copy link
Author

Turbine1991 commented May 19, 2020

Just a note, the BSON example doesn't work. I installed BSON on both ends, but the server would not parse it using the settings. Might want to clear up the documentation, if I did something wrong here.

The performance of the library is good. Beats the WS for sure. It's also got a nicer api.

@hans00 hans00 added the bug Something isn't working label May 22, 2020
@hans00
Copy link
Owner

hans00 commented May 23, 2020

Thanks for your issue.

The bug will fix in next version.

The BSON is encode to Buffer, but in WebSocket is sent as string (binary is reserve for blob transfer).
So temporary solution is toString.

parserOptions: {
  serialize: val => BSON.serialize(val, false, true, false).toString('ascii'),
  deserialize: bufStr => BSON.deserialize(Buffer.from(bufStr, 'ascii'))
}

@Turbine1991
Copy link
Author

You're a bloody legend hans. Thanks mate.

@hans00
Copy link
Owner

hans00 commented Oct 7, 2021

That is fixed

@hans00 hans00 closed this as completed Oct 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants