XSockets / WebSockets无法从托管之外的其他计算机访问

时间:2014-06-24 23:02:07

标签: c# .net html5 websocket xsockets.net

我正在使用WebSockets开发一个站点,我正在使用XSockets.NET来实现整个WebSockets服务器。

此外,我能够从开发机器中访问XSocket.NET控制器,但我无法从另一台机器上访问它。

BTW,这不是DNS问题,因为网站本身可以从任何其他机器浏览:它是WebSockets的东西。

目前我在Firebug中收到以下错误: Firefox无法建立与服务器[...] 的连接,其中服务器是端口7532上的整个主机名。

我可以提供一个示例代码,说明我如何配置和启动整个WebSockets服务器:

IXSocketServerContainer server = Composable.GetExport<IXSocketServerContainer>();
List<IConfigurationSetting> serverConfig = new List<IConfigurationSetting>();
serverConfig.Add(new ConfigurationSetting("ws://[host name]:7532", new HashSet<string> { "*" }));
server.StartServers(configurationSettings: serverConfig);

此外,整个XSockets.NET托管在Windows服务中,我使用开箱即用的XSockets.NET JavaScript API连接到XSocket.NET控制器:

// This will work as expected when I open my site from the development machine
var conn = new XSockets.WebSocket("ws://[host name]:7352/[controller name]");

conn.on(XSockets.Events.open, function (clientInfo) {
    conn.subscribe("[Action name]", function (message) {
    });
});

什么会阻止其他机器连接到整个WebSocket服务器?我错过了什么?

2 个答案:

答案 0 :(得分:2)

我已经解决了,这是一个最小的改变。

似乎XSockets.NET需要配置WebSocket以侦听任何 IP和任何主机。也就是说,整个主机应该是0.0.0.0:7532

令人惊讶的是,I've found the solution in a comment on this XSockets.NET documentation page (Creating custom configuration ...)

  

VJ:   好。所以我对上面提到的问题有了更新。有可能   解决方案,无论如何它都适合我。

     
      
  1. 在CustomConfigLoader中,我要将ip地址添加为0.0.0.0,这意味着我的XSockets服务器将从任何IP地址进行侦听。因此,代码看起来像这样:var   URL = “WS://0.0.0.0:4502 /”;

  2.   
  3. 在Javascript中我将使用window.location.hostname,它指向应用程序的主机,本质上是知道的服务器   客户端,我正在使用我的XSockets。

  4.   

我已经在我的代码中做了第二步,首先是制作技巧的原因(在我的情况下,我没有使用CustomConfigLoader,但我刚刚添加了ConfigurationSetting 0.0.0.0:7352作为主机IP /主机名)。

答案 1 :(得分:1)

如果您运行TCP扫描,是否真的可以看到该端口从外部打开?

您是否尝试过使用wss://(安全)连接?您的服务或托管服务提供商可能具有透明proxy that is not websocket friendly。安全可以避免代理问题。

最新版本的XSocket.net中有no documentation for SSL/TLS,但可能非常similar to the older version