简体   繁体   English

如何从公司代理后面的位置打开到云的Websocket连接

[英]How do I open a websocket connection to cloud from location behind corporate proxy

I have a nodejs websocket server running in the cloud to which I can make a secured web socket connection from any location outside of corporate firewall. 我有一个在云中运行的nodejs websocket服务器,可以从公司防火墙外部的任何位置建立安全的Web套接字连接。 Now, how can I provide proxy information while creating a websocket connection from a resource behind corporate proxy (on-premise)? 现在,如何在公司代理后面的资源(内部部署)中创建Websocket连接时如何提供代理信息? I am using this nodejs module from https://github.com/websockets/ws . 我正在从https://github.com/websockets/ws使用此nodejs模块。

I get EHOSTUNREACH error when I execute following code. 执行以下代码时,出现EHOSTUNREACH错误。 Please note there is no vpn connection between cloud resource and the on premise resource. 请注意,云资源和内部资源之间没有vpn连接。

**var wss = new WebSocket('wss://cloudserver:443', {
        rejectUnauthorized: false
    });**

With a sample code like below, I am able to make http connection to cloud from a resource behind corporate proxy using proxy information , but can't figure out how to make it work with the web sockets. 使用下面的示例代码,我可以使用代理信息从公司代理后面的资源建立与云的http连接,但无法弄清楚如何使其与Web套接字一起使用。

    **var Http = require('http');

    var req = Http.request({
        host: 'proxy',
        port: 8080,
        method: 'GET',
        path: 'http://cnn.com/' // full URL as path
    }, function (res) {
        res.on('data', function (data) {
            console.log(data.toString());
        });
    });

    req.end()

**

I also looked at following http://blog.vanamco.com/proxy-requests-in-node-js/ and it seems to have what I need, but as I am new to nodejs I am somewhat lost here. 我还查看了以下http://blog.vanamco.com/proxy-requests-in-node-js/ ,它似乎满足了我的需要,但是由于我是Nodejs的新手,所以我在这里有些迷失。

Well EHOSTUNREACH implies that no network route can be found to the IP address that DNS provides for the targeted server. EHOSTUNREACH意味着找不到到DNS为目标服务器提供的IP地址的网络路由。

This can either be a DNS error from the local DNS server (wrong IP address) or a routing error (wrong or missing route to that IP address) or possibly there is purposely no route to the target address (private network or corp network blocking things). 这可能是来自本地DNS服务器的DNS错误(错误的IP地址),也可能是路由错误(错误地或丢失了指向该IP地址的路由),或者可能是故意没有到目标地址的路由(专用网络或公司网络阻止了此事) )。

You could check the DNS side of things by seeing if you get the same IP address for that host from both work and home. 您可以通过查看工作和家庭中该主机的IP地址是否相同来检查DNS方面。 A simple ping hostname will show you the IP address. 一个简单的ping hostname名将为您显示IP地址。 If the target server supports ping requests, it will also tell you if the host is reachable. 如果目标服务器支持ping请求,它还将告诉您主机是否可访问。 You could also examine tracert hostname from both home and work and see where things get lost. 您还可以在家庭和工作场所检查tracert hostname ,并查看丢失的地方。

I was able to connect to my cloud instance by providing proxy information using websocket-node ( https://github.com/theturtle32/WebSocket-Node/ ) module as below. 通过使用如下所示的websocket-node( https://github.com/theturtle32/WebSocket-Node/ )模块提供代理信息,我能够连接到我的云实例。 The actual url is replaced with 'xxx' for security reasons. 出于安全原因,实际的网址将替换为“ xxx”。 Thanks everyone who tried to help. 感谢所有尝试提供帮助的人。

var fs = require('fs');
var client = new WebSocketClient();
var tunnel = require('tunnel');
var net = require('net');

var tunnelingAgent = tunnel.httpsOverHttp({
  rejectUnauthorized: false,
  proxy: {
      host: 'xxxxxxxx',
      port: 8080,
  }
});



var requestOptions = {
    agent: tunnelingAgent,
    rejectUnauthorized: false,
    strictSSL: false,
    requestCert: false,
};

var headers = {

};


client.connect('wss://xxxxxx',null, 'xxxxxx', headers, requestOptions);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM