简体   繁体   English

使用命名管道的节点HTTP请求

[英]Node HTTP request using a named pipe

I am trying to request a GET through an existing named pipe. 我正在尝试通过现有的命名管道请求GET。 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). 这是为了解决Azure上的Node进程由IISNode包装的事实,因此没有自己的端口,而是被赋予了命名管道(作为PORT环境变量)。 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 ). Node的net.Server类知道如何处理命名管道,这解释了HTTP路由工作正常的原因(因为http .Server似乎使用相同的接口 )。 From the docs: 从文档:

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

On Windows, the local domain is implemented using a named pipe. 在Windows上,本地域是使用命名管道实现的。 The path must refer to an entry in \\?\\pipe\\ or \\.\\pipe. 该路径必须引用\\?\\ pipe \\或\\。\\ 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: 不要忘记JavaScript字符串转义需要使用双反斜杠指定路径,例如:

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. 我想做的是重用此现有的命名管道将请求发送到侦听服务器,从而绕过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). named-pipes软件包在这里似乎并不适用,因为它似乎提供了一个太高级的接口,与我正在寻找的低级套接字/ EventEmitter性质不一样)。 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);
    })
});

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. 我交谈过的一些.NET家伙给人的印象是,这是行不通的,因为他们认为 (不是确定的信息)命名管道仅接受一个客户端对该管道的读写。

Related: Calling localhost urls on Azure's IISNode 相关: 在Azure的IISNode上调用本地主机URL

Can you try using process.env.PORT instead of app.config.port and see if it works. 您可以尝试使用process.env.PORT代替app.config.port并查看它是否有效。 If it does not, the only option is to use Azure VM. 如果不是,唯一的选择是使用Azure VM。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM