nodejs socket.io 与 IIS 节点

发布于 2024-12-13 14:00:47 字数 664 浏览 3 评论 0原文

我已经在 Windows Vista/IIS 7 中使用 iis 节点尝试了使用 node.js 进行一些操作。我的想法是在 asp .net mvc 应用程序上使用服务器脚本连接到另一个套接字服务器并以持久方式服务请求。

我在 https://github.com/tjanczuk/iisnode 下载了适用于 IIS 7 的 iisnode 版本,并且能够使用 web.config 和 IIS 模块配置中的 http 处理程序映射运行基本的“hello world”http 服务器管道。

我正在尝试使用node.js 中的socket.io 库。如果我编写服务器和客户端,这将独立工作。但与 IIS 节点一起使用时失败。

我在进一步下降时遇到问题。诸如

  • 如何在 asp .net mvc 项目中包含 npm 模块?我试过 将node_modules放在节点脚本的文件夹中,但这确实 没有帮助。基本上 require('socket.io') 命令可以工作,但是 套接字连接等,根本就失败了。
  • 如何拥有一个套接字 来自客户端的连接,它将继续侦听来自的更新 服务器(如 COMET) - 正如我所说,我正在尝试使用 socket.io

之前有人尝试过吗?

I have tried something with node.js in windows vista/IIS 7 using iis node. My idea is to use a server script on the asp .net mvc application to connect to another socket server and serve requests on a persistent fashion.

I downloaded the iisnode version at https://github.com/tjanczuk/iisnode for IIS 7 and able to run the basic 'hello world' http server pipe using http handler mappings in web.config and IIS modules configuration.

I am trying to use socket.io library from node.js. This works independently if I write a server and client. But fails when used with IIS node.

I am having problems going down further. Problems like

  • How to include the npm modules in the asp .net mvc project? I tried
    putting the node_modules in the folder of node scripts, but that did
    not help. Basically the require('socket.io') command works, but the
    socket connection etc., simply fails.
  • How to have a socket
    connection from client which will keep listening for updates from
    server(like COMET) - As I said I am trying to use socket.io

Any body tried this before?

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

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

发布评论

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

评论(3

狂之美人 2024-12-20 14:00:47

回读几个月前,IIS下的Socket.IO不支持WebSocket支持,无论轮询有多长。

这是几个月前的事,我现在遇到了同样的问题并试图解决。

正如托马斯写道:

请注意iisnode不支持websocket传输,但是
使用 socket.io 仍然可以与其他基于 HTTP 的传输一起使用
就像 HTTP 长轮询:

io.configure(function() {
    io.set('transports', ['xhr-polling']);
});

看起来截至2012年2月23日,该功能仍不支持。

需要通过IIS吗?您是否可以选择使用纯 Socket.IO/Node 选项来消除 IISNode?如果您需要具有后备功能的完整 WebSocket 支持,这看起来是唯一的选择,除非有其他建议?

Reading back a few months ago, WebSocket support is not supported with Socket.IO under IIS, however long polling is.

This was a few months ago, and I'm running up against the same issue now and trying to resolve.

As Tomasz writes:

Please note that iisnode does not support websocket transport, but
using socket.io is still possible with other HTTP-based transports
like HTTP long polling:

io.configure(function() {
    io.set('transports', ['xhr-polling']);
});

By the looks of it, as of Feb 23, 2012, this functionality is still not supported.

Do you need to go through IIS? Do you have the option of going with a pure Socket.IO/Node option, eliminating IISNode? If you need full WebSocket support with fallback capability, this looks like the only option, unless there are other suggestions?

朮生 2024-12-20 14:00:47

这可能与您的问题有关,也可能无关。我没有对 socket.io 做太多事情,但是我计划做一些与您所描述的非常相似的事情。在阅读 iisnode 的源代码时,我在 cnodehttpmodule.cpp 中发现了以下代码:

this->applicationManager->GetEventProvider()->Log(L"iisnode received a new http request", WINEVENT_LEVEL_INFO);

// reject websocket connections since iisnode does not support them
// http://tools.ietf.org/html/draft-ietf-hybi-thewebsocketprotocol-17#page-17

PCSTR upgrade = pHttpContext->GetRequest()->GetHeader(HttpHeaderUpgrade, NULL);
ErrorIf(upgrade && 0 == strcmp("websocket", upgrade), ERROR_NOT_SUPPORTED); 

在我看来,如果“websocket”包含在请求的标头中,它将被拒绝。我需要阅读 websocket 协议才能更好地理解这意味着什么。

我将是第一个承认我不太了解 Websocket 与长时间运行的请求有何不同的人。然而,据我了解,socket.io 将在不支持 websocket 的旧浏览器上运行。

我建议您尝试将传输设置为 xhr-polling 或 jsonp-polling。它有点打败了使用 Node.js 的酷炫因素,但它可能会帮助您解决问题。

This may or may not be related to your problem. I haven't done much with socket.io, however I was planing to do something very similar to what you're describing. When reading through the source for iisnode, I found the following code in cnodehttpmodule.cpp:

this->applicationManager->GetEventProvider()->Log(L"iisnode received a new http request", WINEVENT_LEVEL_INFO);

// reject websocket connections since iisnode does not support them
// http://tools.ietf.org/html/draft-ietf-hybi-thewebsocketprotocol-17#page-17

PCSTR upgrade = pHttpContext->GetRequest()->GetHeader(HttpHeaderUpgrade, NULL);
ErrorIf(upgrade && 0 == strcmp("websocket", upgrade), ERROR_NOT_SUPPORTED); 

It looks to me as though if "websocket" is included in the header of the request, it will be rejected. I would need to read up on the websocket protocol to better understand exactly what this means.

I'll be the first to admit that I don't know overly well how websockets differ from a long running request. As I understand it, however, socket.io will work on older browsers that do not support websockets.

I recommend you try to set the transport to just xhr-polling or jsonp-polling. It kinda defeats the cool factor of using node.js but it might help you reach a resolution to your problem.

草莓味的萝莉 2024-12-20 14:00:47

如果您的 socket.io Web 应用程序托管在 IIS 虚拟目录中,则与自托管情况相比,必须修改 socket.io 配置。请参阅 http://tomasz.janczuk.org /2013/01/hosting-socketio-websocket-apps-in-iis.html 了解详细信息。

此外,从版本 0.2.x 开始,iisnode 确实支持 Windows 8 和带有 IIS 8 的 Windows Server 2012 上的 WebSocket。查看 http://tomasz.janczuk.org/2012/11/how-to-use-websockets-with-nodejs-apps.html 了解详细信息。

If your socket.io web application is hosted in an IIS virtual directory, socket.io configuration must be modified compared to a self-hosted case. Please see http://tomasz.janczuk.org/2013/01/hosting-socketio-websocket-apps-in-iis.html for details.

Also, as of version 0.2.x, iisnode does support WebSockets on Windows 8 and Windows Server 2012 with IIS 8. Check out http://tomasz.janczuk.org/2012/11/how-to-use-websockets-with-nodejs-apps.html for details.

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