Connect event in net

operate according to the code in the nodejs playbook, and find that when a new user connects to the node server, the connect event will not be triggered
code is as follows

node version 8.12

const events = require("events");
const net = require("net");

const server = net.createServer(function(client) {
  const id = `${client.remoteAddress}:${client.remotePort}`;
  client.on("connect", function() {
    console.log(123123213);
  });

    //connection

  client.on("data", function(data) {
    console.log(data);
    data = data.toString();
  })
});
server.listen(8081);

connection code

telnet 127.0.0.1 8081
Sep.08,2021

in your callback function. There will be no connect events.

-
update:

I don't know what your book says, but
is already connected when it enters the callback, so how can it trigger connect again.

< hr >

Node.js net module documentation is not mentioned.

stackoverflow related questions and answers .

Menu