Answer the question
In order to leave comments, you need to log in
How to wrap a tcp socket connection between two servers in a promise?
There is an authorization and session storage server.
To simplify to a minimum:
const net = require('net');
const server = net.createServer((socket) => {
socket.on('data', (data) => {
//обрабатываем данные
socket.write(data); //отправляем обработанные
});
socket.on('end', () => {});
});
server.listen(1333, () => {
console.log('server bound');
});
const net = require('net');
const client = new net.Socket();
client.setEncoding('utf8');
client.connect('1333','0.0.0.1', ()=>{});
client.write(JSON.stringify({ param : data.toString()}));
client.on('data', (data) => {
//обрабатываем полученные от сервера результаты
});
Answer the question
In order to leave comments, you need to log in
It can also be a regular callback. The main thing is that your logic is executed asynchronously.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question