G
G
Galdar Turin2021-02-16 18:41:14
Node.js
Galdar Turin, 2021-02-16 18:41:14

How to connect a client via NET to the desired event?

It turns out that from the client I want to connect to the control event, and not to the default data, in socket.io it’s easy to do this, but as in net, I can’t find it in the docks, tell me pliz.

// Клиент
const client = net.createConnection({port: 0000 }, () => {
  // 'connect' listener.
  console.log('connected to server!');
  client.write('world');
});

client.on('data', (data) => {
  console.log(data.toString());
  client.end();
});

client.on('end', () => {
  console.log('disconnected from server');
});

// Сервер
net.createServer( socket => {

    socket.on('control', data => {

        console.log('control')
        console.log(data)

    })

})
.listen(0000, error => {

    console.log(error);

});

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question