Skip to content

Instantly share code, notes, and snippets.

@fyx99
Created April 12, 2023 19:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fyx99/cb6389e3c1942729cdbfc7ad3a9e1c71 to your computer and use it in GitHub Desktop.
Save fyx99/cb6389e3c1942729cdbfc7ad3a9e1c71 to your computer and use it in GitHub Desktop.
Node.Js Example TCP Server
var net = require('net');
var server = net.createServer(function(socket) {
socket.write('Hello TCP!');
socket.pipe(socket);
// for testing purposes we handle client side errors
socket.on('error', function(err) {
if (err.code === 'ECONNRESET') {
console.error('Client closed connection');
} else {
console.error(err);
}
});
});
server.listen(4444, '127.0.0.1');
// run this server with
// node app-tcp.js
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment