Skip to content

Instantly share code, notes, and snippets.

@fyx99
Created April 12, 2023 19:45
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
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