如何使websockets通过node.js中的代理 [英] How to make websockets to go through a proxy in node.js

查看:102
本文介绍了如何使websockets通过node.js中的代理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

概括这将是一个问题......如何让websockets通过node.js中的代理?

Generalizing that would be the question... how to make websockets to go through a proxy in node.js?

在我的特定情况下我正在使用pusher.com和 node.js客户端库他们推荐。查看代码内部我想知道一些关于我应该更改的提示,以使这个库与代理一起工作......你可以查看代码这里

In my particular case I'm using pusher.com with the node.js client library they recommend. Looking inside the code I would like to know some hints on what I should change in order to make this library to work with a proxy... you can take a look in the code here

也许我应该以某种方式替换或修改 websockets模块

Maybe I should somehow replace or modified the websockets module that is being used by the library?

编辑

感谢您的回答/评论!需要考虑的几件事(对不起,如果我对其中的一些/全部错了,只是学习):

Thanks for your answers/comments! A couple of things to take into consideration (excuse me if I'm wrong with some/all of them, just learning):


  • I不想创建代理服务器。我只是想在我的公司内使用现有的代理服务器来代理我的websockets请求(特别是pusher.com)。

  • 只是为了让你知道,如果我使用像这样的接收器对于Windows Proxifier ,我设置规则以检查到端口443的所有连接是否通过代理服务器 proxy-my.coporate.com:1080(类型SOCKS5)它就像一个魅力。

  • 但我不想这样做。我想在我的节点js代码中以编程方式配置此代理服务器(即使涉及修改我提到的推送器库)

  • 我知道如何执行此操作使用请求模块进行HTTP查找(查找提及如何使用代理的部分)。

    • 我想要 websockets 类似的东西。

    • I don't want to create a proxy server. I just want to use an existent proxy server within my company in order to proxified my websockets requests (particularly pusher.com)
    • Just to let you know, if I use a proxifier like the one for windows Proxifier and I set up the rule to inspect for all connections to port 443 to go through the proxy server proxy-my.coporate.com:1080 (type SOCKS5) it works like a charm.
    • But I don't want to go this way. I want to programatically configuring this proxy server within my node js code (even if that involved to modified the pusher library I mentioned)
    • I know how to do this for HTTP using Request module (look for the section that mentions how to use a proxy).
      • I want a similarly thing for websockets.

      推荐答案

      大多数网络代理尚不支持websockets。最好的解决方法是通过指定wss://(websocket安全协议)来使用加密:

      Most web proxies don't support websockets yet. The best workaround is to use encryption by specifying wss:// (websocket secure protocol):

      wss://ws.pusherapp.com:[port]/app/[key]
      

      这篇关于如何使websockets通过node.js中的代理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆