我正在尝试在Roder中使用net.connect连接到节点http服务器套接字(expressJs),以将该套接字传递给我的repl,以便基本上可以连接到我的http服务器并启动命令。
[尝试此操作时,我第二次启动副本时遇到错误EPIPE。
这是副本的代码:
const args = process.argv.slice(2);
if (args.length < 1) {
process.exit(1);
}
const url = args[0];
const [host, port] = url.split(':');
//this will get the url to connect to
const socket = net.connect(parseInt(port), host);
process.stdin.pipe(socket);
socket.pipe(process.stdout);
Console.start({
expose: { container, Metric:metricsObject},
socket:socket
});
启动功能:
start(options = {}) {
const { expose, socket } = options;
const repl = REPL.start({
eval: promisableEval,
terminal:true,
input: socket,
output: socket,
});
Object.assign(repl.context, expose);
}
http服务器正在运行:
const http = this.express
.listen(this.config.web.port, () => {
const { port } = http.address();
this.logger.info(`[p ${process.pid}] Listening at port ${port}`);
resolve();
});
this.express
只是express的一个实例:this.express = express();
net.connect(parseInt('3000/path/item'), 'http://mine.example.com');
由于多种原因,它不起作用。
除非您是http协议方面的优秀程序员专家,否则不应使用
net.connect
与http服务器交谈。尝试改用http.clientRequest。传递给net.connect的主机名应该是原始计算机名,例如
'mine.example.com'
,并且不能在协议说明符之后。端口,相似。
- [抱歉,我不知道您要使用stdin和stdout做什么。但是您的
socket
直到连接操作完成且您收到一个宣布该事件的事件时,才可以使用。