gpt4 book ai didi

tcp - Node.js TCP 转发器

转载 作者:可可西里 更新时间:2023-11-01 02:36:41 29 4
gpt4 key购买 nike

我有以下简单的 NodeJS 脚本,想稍微修改一下....

var sys = require( 'sys' ), net = require( 'net' );

var outputserver = net.createServer( function( stream ) {
stream.addListener( 'data', function( data ) {
sys.puts( data );
//Want to output anything from the clientserver data here
});
}).listen( 7001, 'localhost' );

var clientserver = net.createServer( function( stream ) {
stream.addListener( 'data', function( data ) {
sys.puts( data );

});
}).listen( 7000, 'localhost' );

我需要将来自“clientserver”的任何内容输出到“outputserver”流。将有 50-60 个客户端连接到“客户端服务器”

最佳答案

这应该有效:

var util = require('util'), net = require('net');
var outServer = net.createServer(function(outStream) {
outStream.on('data', function(data) {
util.puts(data);
});
var inServer = net.createServer(function(inStream) {
inStream.pipe(outStream, {end: false});
});
inServer.listen(7001, 'localhost');
});
outServer.listen(7000, 'localhost');

关于tcp - Node.js TCP 转发器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5142666/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com