gpt4 book ai didi

c# - XSockets/WebSockets 无法从主机之外的其他机器访问

转载 作者:太空宇宙 更新时间:2023-11-04 16:27:34 26 4
gpt4 key购买 nike

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

此外,我可以从开发机器中访问 XSocket.NET Controller ,但无法从另一台机器访问它。

顺便说一句,这不是 DNS 问题,因为网站本身可以从任何其他机器上浏览:它与 WebSockets 有关。

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

我可以提供有关如何配置和启动整个 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 连接到 XSockets.NET Controller :

// 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 服务器?我错过了什么?

最佳答案

我已经解决了,而且是最小的改动。

似乎 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: Ok. So I have an update to the problem I mentioned above. A possible solution, which it is for me anyway.

  1. In the CustomConfigLoader, I am going to add the ip address as 0.0.0.0, which means my XSockets server will listen from any ip address. Therefore, the code would look like this: var url="ws://0.0.0.0:4502/";

  2. In the Javascript I will use window.location.hostname, which points to the host of the application, essentially the server as know to the client, I am using my XSockets with.

第二步已经是我在代码中的做法了,第一步是成功的原因(在我的例子中,我没有使用 CustomConfigLoader,但我只是添加了一个 ConfigurationSetting0.0.0.0:7352 作为主机 IP/主机名)。

关于c# - XSockets/WebSockets 无法从主机之外的其他机器访问,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24397738/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com