getstation / stream-json-rpc

Easy bi-directionnal RPC for node/electron/browser, using the transport that you need.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

bind on IP does not work

fas3r opened this issue · comments

commented

Hello,

I might misunderstand but I always see 127.0.0.1 with the port 9229 when using netstat -nltp even when giving the appropriate options to getServer method of stream-node-ipc, it's not possible to bind it to a different interface/port ?

Thanks

This should work as intended, options just overrides any default value:

Object.assign(ipc.config, options);

Could you share the config that you are using? I would test it to see if I can get the same behaviour.

commented

Hello @magne4000 ,

Thanks for your feedback, indeed it should, I did something like that for the server :

  const ipcServer = getServer('my-namespace', {
      requestCert: false,
      rejectUnauthorized:false,
      interface: {
        localAddress: '127.0.0.1',
        localPort: 8888,
        family: 4
      }
  });

I guess it should be enough.

Btw great repos

commented

Hello @magne4000 ,

Did you have a chance to try by any chance ?

thanks

I just saw you had a typo, it's interfaces: not interface:. Nevertheless, I only created helpers for UNIX sockets (ipc.connect() and ipc.server()) and not net sockets (ipc.connectNet() and ipc.serveNet()).
You can easily implement your own helpers by copying and modifying the following functions in your own code

export const getClient = (appspace: string, id: string = 'client', options: object = {}): Client => {
const ipc = new nodeipc.IPC();
ipc.config.appspace = appspace;
ipc.config.id = id;
ipc.config.silent = true;
ipc.config.retry = 1000;
ipc.config.rawBuffer = true;
ipc.config.encoding = 'hex';
Object.assign(ipc.config, options);
ipc.connectTo('server', () => {});
return ipc.of.server;
};
export const getServer = (appspace: string, options: object = {}): Server => {
const ipc = new nodeipc.IPC();
ipc.config.appspace = appspace;
ipc.config.id = 'server';
ipc.config.silent = true;
ipc.config.retry = 1000;
ipc.config.rawBuffer = true;
ipc.config.encoding = 'hex';
Object.assign(ipc.config, options);
ipc.serve(() => {});
ipc.server.start();
return ipc.server;
};

commented

Hello @magne4000 ,

Yes sorry, I tought I updated the comment regarding the typo.

Yes I will do so, I just wanted to avoid modifications as you might make changes in the futures.

Feel free to close the ticket,

Thanks

commented

Hello @magne4000 ,

Do you think it's something that you could implement ? Or maybe are you open to PR for that ?

Thanks

I'm open to PR for that ! 👍

commented

@magne4000 you are amazing, thank you very much