Is it possible to run a tcp server
in nodejs on multiple ports?
var socketServer = net.createServer(function (socket) {
socket.on('end', function () {
});
socket.on('error', function (error) {
});
return socket;
}).listen(8080);
Any ideas how the above could also run on port 8888
?
The best you can do is extract your connection handler and create multiple server instances:
function connHandler(socket) {
socket.on('end', function() {
});
socket.on('error', function(error) {
});
}
net.createServer(connHandler).listen(8080);
net.createServer(connHandler).listen(8088);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With