Node.js 客户获得';错误请求';来自服务器的响应
我正在使用nodejs网络库。 在本地,一切正常,我可以通过客户端连接到服务器,将数据发送到服务器,然后得到响应 但一旦部署到服务器上(使用traefik),当我运行client-app.js时,我会得到:Node.js 客户获得';错误请求';来自服务器的响应,node.js,sockets,traefik,Node.js,Sockets,Traefik,我正在使用nodejs网络库。 在本地,一切正常,我可以通过客户端连接到服务器,将数据发送到服务器,然后得到响应 但一旦部署到服务器上(使用traefik),当我运行client-app.js时,我会得到: Connected Received: HTTP/1.1 400 Bad Request Content-Type: text/plain; charset=utf-8 Connection: close 400 Bad Request Connection closed Traefik
Connected
Received: HTTP/1.1 400 Bad Request
Content-Type: text/plain; charset=utf-8
Connection: close
400 Bad Request
Connection closed
Traefik被配置为将每个到达“my address.com”的请求重定向到docker容器(其中运行server app.js)上的1337端口
这是我的密码:
server-app.js:
const net = require('net');
const PORT = 1337;
const HOST = '0.0.0.0';
var server = net.createServer(function(socket) {
socket.write('Echo server\r\n');
//socket.pipe(socket);
socket.on('data', (data) => {
console.log('DATA RECEIVED')
socket.write('GOT DATA', data)
});
});
server.on('connection', (socket)=> {
console.log('Connection from: ', socket.remoteAddress)
});
server.listen(PORT, HOST, () => {
console.log(`SERVER IS UP. PORT ${PORT}`)
})
client-app.js:
const net = require('net');
const PORT = 443;
const HOST = 'my-addres.com';
var client = new net.Socket();
console.dir(client.connect)
client.connect({port: PORT, host: HOST}, function() {
console.log('Connected');
client.write('Hello, server! Love, Client.\n');
var counter = 1;
setInterval(()=>{client.write(`Data nr ${counter}\n`); counter += 1}, 1000)
});
client.on('data', function(data) {
console.log('Received: ' + data);
//client.destroy(); // kill client after server's response
});
client.on('close', function() {
console.log('Connection closed');
});
您的客户机和服务器不使用HTTP协议,而是在TCP之上使用自己的应用程序协议。但看起来您已经将Traefik配置为HTTP路由器,因为您收到的是HTTP响应。由于您不使用HTTP,因此不应使用HTTP,而应使用a。您的客户端和服务器不使用HTTP协议,而是在TCP之上使用自己的应用程序协议。但看起来您已经将Traefik配置为HTTP路由器,因为您收到的是HTTP响应。因为您不使用HTTP,所以不应该使用HTTP,而应该使用