使用命名管道节点HTTP请求 [英] Node HTTP request using a named pipe

查看:174
本文介绍了使用命名管道节点HTTP请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过现有的命名管道请求GET。这是要解决的事实,在Azure上节点的进程被IISNode包裹着,因此不拥有自己的港口,而是被赋予了命名管道(如 PORT 环境变量)。节点的 net.Server 类知道如何处理命名管道,这就解释了为什么HTTP路由工作正常(如 HTTP .Server `似乎使用相同的接口)。从文档:

I am trying to request a GET through an existing named pipe. This is to work around the fact that Node processes on Azure are wrapped by IISNode, thus not having a port of their own, but rather being given a named pipe (as the PORT environment variable). Node's net.Server class knows how to handle named pipes, which explains why HTTP routing works fine (as http.Server` seems to use the same interface). From the docs:

类:net.Server 服务器上。听(路径[回调])

Class: net.Server on server.listen(path[, callback])

在Windows中,本地域中使用命名管道来实现。该
  路径必须引用\\?\\管\\或输入\\。\\管道。任何字符
  是允许的,但后者可能会做管道名称的一些处理,
  如解决..序列。尽管出场,管道名称
  空间是平坦的。管道不会持续下去,他们将被删除当最后一个
  提及他们关闭。不要忘记的JavaScript字符串转义
  要求用双反斜线来指定路径,如:

On Windows, the local domain is implemented using a named pipe. The path must refer to an entry in \?\pipe\ or \.\pipe. Any characters are permitted, but the latter may do some processing of pipe names, such as resolving .. sequences. Despite appearances, the pipe name space is flat. Pipes will not persist, they are removed when the last reference to them is closed. Do not forget JavaScript string escaping requires paths to be specified with double-backslashes, such as:

但是,这是在接收/收听结束。我想要做的就是重新使用这个现有的命名管道发送请求到监​​听服务器,绕过IISNode外部并发症。的这甚至可能吗?的(即命名管道包装似乎并不适用于此,因为它似乎提供了过高级别的接口,并不像低级别的插座/ EventEmitter性质我找的)。有<一个href=\"http://stackoverflow.com/questions/11750041/how-to-create-a-named-pipe-in-node-js\">indications它的可能的是不可能的,但似乎关心显式创建命名管道,而不是重用现有的,这是我想做的事情。而且它没有说的将无法正常工作的,只知道它是不是的支持

But this is on the receiving/listening end. What I would like to do is to re-use this existing named-pipe to send requests to the listening server, bypassing the external complications of IISNode. Is this even possible? (The named-pipes package does not seem to apply here, as it seems to provide a too high-level interface that does not resemble the low-level socket/EventEmitter nature I am looking for). There are indications that it might not be possible, but that seems to concern explicitly creating named pipes, not reusing existing ones, which is what I want to do. And it does not say will not work, only that it is not supported.

我想这样做是为了发送请求,但我没能得到回应。它只是挂无所事事。

I tried doing this to send a request, but I am failing to get a response. It simply hangs doing nothing.

var namedPipeLocalDomain= app.config.port;

var options = {
    hostname: namedPipeLocalDomain,
    path: util.format('/api/%s', restPayloadObject.servicepath),
    method: 'GET'
};

logger.info('Creating connection using named pipe, ', namedPipeLocalDomain);

var req = http.request(options, function(res) {
    logger.info('STATUS: ' + res.statusCode);
    logger.info('HEADERS: ' + JSON.stringify(res.headers));

    res.setEncoding('utf8');
    res.on('data', function (chunk) {
        body += data
        logger.info('BODY: ' + chunk);
    });
    res.on('end', function() {
        console.log('No more data in response.')
        console.log(body);
    })
});

一些.NET家伙我都讲过了IM pression,作为他们的这是不行想到的(不明确的信息),命名管道只接受一个客户机读取/写入管。

Some .NET guys I talked were of the impression that this won't work as they thought (not definitive info) a named pipe only accepts one client reading/writing to the pipe.

相关报道:调用在Azure上的IISNode 本地主机网址

Related: Calling localhost urls on Azure's IISNode

推荐答案

您可以尝试使用,而不是app.config.port process.env.PORT,看看它是否工作。如果没有,唯一的选择就是使用Azure的VM。

Can you try using process.env.PORT instead of app.config.port and see if it works. If it does not, the only option is to use Azure VM.

这篇关于使用命名管道节点HTTP请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆