Monday 10 April 2017

Continuously check for connection to specific URL and port

How do I continuously check to see if there is an active connection to a specific url and port? I am able to get this initially by going with:

const net = require('net');
const testCon = new net.Socket();

testCon.connect('12.12.123.123:8000', function () {
    // connected
});

testCon.on('disconnect', function () {
  // not connected 
});

I didn't want to wrap it in a setInterval function. That seems hacky to me. There has to be a better way to accomplish this.



via Ryan W.

No comments:

Post a Comment