Building applications
Creating a TCP Server
var net = require('net');
var HOST = '127.0.0.1';
var PORT = 6969;
// Create a TCP server instance, and call the listen function to start listening on the specified port
// The callback function passed to net.createServer() will be the event handler for the "connection" event
// In each "connection" event, the socket object received by this callback function is unique
var server = net.createServer();
server.listen(PORT, HOST);
console.log('Server listening on ' +
server.address().address + ':' + server.address().port);
server.on('connection', function(sock) {
console.log('CONNECTED: ' +
sock.remoteAddress +':'+ sock.remotePort);
});Creating a TCP Client
Last updated