maximegris / node-websockify

A simple WebSocket-to-TCP proxy/bridge you can use in NodeJS
MIT License
36 stars 17 forks source link

how to handle the situation of multiple target? #14

Open lvbirui opened 3 years ago

lvbirui commented 3 years ago

is there any way to connect multiple target VNC server by this package?

Craigzyc commented 3 years ago

Each listener would need a dedicated port but multiple instances of websockify could be created within one node instance.

I haven't tested this at all, but something like this should work


var websockify = require('@maximegris/node-websockify');
var vncServers = [
  {
    ip:'192.168.0.2',
    vncPort: 5901,
    nodePort: 5901
  },
  {
    ip:'192.168.0.2',
    vncPort: 5901,
    nodePort: 5902
  }
]

var vncWebsockifies = []

for (var i = 0; i < vncServers.length; i++) {
  vncWebsockifies[i] = websockify({
  source: '127.0.0.1:' + vncServers[i].nodePort,
  target: vncServers[i].ip + ':' + vncServers[i].vncPort,
  web : './directory',
  cert: 'certSSL',
  key: 'certSSL-key'
  });
}
lvbirui commented 3 years ago

Each listener would need a dedicated port but multiple instances of websockify could be created within one node instance.

I haven't tested this at all, but something like this should work


var websockify = require('@maximegris/node-websockify');
var vncServers = [
  {
    ip:'192.168.0.2',
    vncPort: 5901,
    nodePort: 5901
  },
  {
    ip:'192.168.0.2',
    vncPort: 5901,
    nodePort: 5902
  }
]

var vncWebsockifies = []

for (var i = 0; i < vncServers.length; i++) {
  vncWebsockifies[i] = websockify({
  source: '127.0.0.1:' + vncServers[i].nodePort,
  target: vncServers[i].ip + ':' + vncServers[i].vncPort,
  web : './directory',
  cert: 'certSSL',
  key: 'certSSL-key'
  });
}

It kindly wrong , i had tested. websokify is just one object,can not handle two adress.

Craigzyc commented 3 years ago

@lvbirui See the answer in the other similar issue. You are correct. You actually need to do a require for each instance by the looks of it