Socket.IO 客户端未与服务器通信

发布于 2024-11-05 12:34:13 字数 522 浏览 1 评论 0原文

因此,我目前正在将 Node.js 应用程序从本地计算机移动到生产服务器。 Socket.IO(版本 0.6.17)似乎在我的服务器上工作正常,但客户端在尝试与服务器通信时出错。

这是一些代码:

<script src='http://cdn.socket.io/stable/socket.io.js'>
    // ...
    var socket = new io.Socket(null, { port: 47556 }).connect();
    // ...
</script>

这是 Google Chrome 的控制台每隔几秒(连续)输出的内容:

GET http://mysite.com:47556/socket.io/xhr-polling//1304476733618 undefined (undefined)

有人提到这可能是由于客户端和 socket.io 版本之间的版本差异造成的,但我不知道如何检查客户端版本。

So I'm currently moving a Node.js application from my local computer to a production server. Socket.IO (version 0.6.17) seems to work fine on my server, but the client errors out when trying to communicate to the server.

Here's some code:

<script src='http://cdn.socket.io/stable/socket.io.js'>
    // ...
    var socket = new io.Socket(null, { port: 47556 }).connect();
    // ...
</script>

And here's what Google Chrome's console outputs after every few seconds (continuously):

GET http://mysite.com:47556/socket.io/xhr-polling//1304476733618 undefined (undefined)

Someone mentioned that it may be due to a version difference between the client and socket.io versions, but I don't know how I'd check the client side version.

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

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

发布评论

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

评论(2

驱逐舰岛风号 2024-11-12 12:34:13

为了安全起见,我将使用与服务器一起分发的 socket.io 客户端脚本。更改您的脚本标记以引用“/socket.io/socket.io.js”(我认为)并让您的应用程序提供服务。这也将使 Flash Sockets 无需将其置于不安全模式(由于跨域问题)即可工作。

To be safe, I would use the socket.io client script distributed with the server. Change your script tag to reference "/socket.io/socket.io.js" (I think) and let your app serve it. This will also Flash Sockets work without having to put it in insecure mode (because of the cross-domain issue).

江挽川 2024-11-12 12:34:13

事实证明,问题在于 WebSocket 不发送正常的 HTTP 请求,导致它们被 nginx 丢弃。来自问答讨论我的托管公司,他们说解决方案是购买一个专用 IP,专门用于监听 WebSocket 连接。

不过,我最终还是使用 Nodester 来托管我的 Node.js 应用程序。

Turns out the problem was that WebSockets don't send normal HTTP requests, resulting in their getting trashed by nginx. From a Q/A discussion with my hosting company, they said the solution would be to buy a private IP which would be specially used to listen for WebSocket connections.

I ended up going with Nodester to host my Node.js app, though.

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