WebSocket 无法在 Internet 上工作

发布于 2024-10-18 17:02:01 字数 882 浏览 0 评论 0原文

我目前有一个 WebSocket 服务器(C#)和一个客户端(JavaScript / HTML5)。这在我的本地网络上效果很好,但是当我监听并使客户端连接到我的“真实”IP(这是我的路由器在全球范围内可识别的IP,即而不是192.168.xx)时,它不起作用。 WebSocket 类确实获得了 readyState1,但是当我将任何内容从客户端发送到服务器(或相反)时,消息不会到达。

我已经将路由器设置为启用端口转发,否则它无论如何都无法工作(我尝试不启用此功能,并且 WebSocket 立即获得 readyState2< /代码>)。

JavaScript 代码:

var ws = new WebSocket("ws://some.real.ip.address:myport");
// For privacy reasons I'd like to keep the address and port private

C# 代码(我正在使用 Nugget 库来实现套接字服务器):

var nugget = new WebSocketServer(myport, "*", "ws://some.real.ip.address:myport");

显然,地址和端口是相同的。

可能是什么原因造成的?当我的计算机作为服务器时,我的 ISP 是否可能不允许套接字连接?如果是这样,WebSocket 为何获得 readyState1

多谢。

I currently have a WebSocket server (C#) and a client (JavaScript / HTML5). This works great on my local network, however when I listen to and make the client connect to my 'real' IP (which is the IP of my router identifiable worldwide, i.e. instead of 192.168.x.x), it doesn't work. The WebSocket class does get a readyState of 1, but when I send anything from the client to the server (or the other way round), the message doesn't arrive.

I already set my router to enable port forwarding, otherwise it wouldn't work anyway (I tried not enabling this and the WebSocket immediately got a readyState of 2).

JavaScript code:

var ws = new WebSocket("ws://some.real.ip.address:myport");
// For privacy reasons I'd like to keep the address and port private

C# code (I'm using the Nugget library to implement a socket server):

var nugget = new WebSocketServer(myport, "*", "ws://some.real.ip.address:myport");

Obviously, the address and port are the same.

What could be the cause of it? Is it possible that my ISP doesn't allow socket connections when my computer is the server? If so, how come the WebSocket does get a readyState of 1?

Thanks a lot.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

段念尘 2024-10-25 17:02:01

这是我的错 - 不确定这个答案是否会对任何人有帮助,但我正在专门监听 /bke ,并且我没有在 JavaScript WebSocket 构造函数中传递它。 ..

It was my fault - not sure if this answer will help anybody, but I'm listening to /bke specifically, and I did not pass this in the JavaScript WebSocket constructor...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文