Created
April 12, 2023 19:45
-
-
Save fyx99/cb6389e3c1942729cdbfc7ad3a9e1c71 to your computer and use it in GitHub Desktop.
Node.Js Example TCP Server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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