客戶端正在以1分鐘的時間間隔向tcp服務器(ip:54.168.66.136,端口:8589)發送數據。我在此服務器上接收數據很好。現在我想要做的是,此tcp服務器必須將數據發送到另一個 服務器(ip:54.165.75.176,端口:8125)。我應該在代碼中更改哪些內容?客戶端向tcp服務器發送數據,tcp服務器向另一臺服務器發送數據
//tcpserver.js code is below
net = require('net');
var http = require('http');
var moment = require('moment');
var fs = require('fs');
var clients = [];
var client = new net.Socket();
var querystring = require('querystring');
net.createServer(function (socket) {
clients.push(socket);
socket.connected_state = "IGN_ON";
socket.on('data', function (data) {
try {
data =""+data;
client.connect(8125, '54.165.75.176', function() {
client.write(data);
});
/*client.on('close', function() {
// console.log('Connection closed');
});*/
}catch (err) {
}
});
socket.on('end', function() {
clients.splice(clients.indexOf(socket), 1);
});
}).listen(8589);
的https://stackoverflow.com/q/45636340/207421 – EJP
stackoverflow.com/q/45636340/207421問題完全重複的客戶端編碼 –