-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds JSDocs and updates example code.
- Loading branch information
1 parent
4b432ba
commit 8c1f11e
Showing
2 changed files
with
69 additions
and
16 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,38 @@ | ||
var portscanner = require('../lib/portscanner.js') | ||
var http = require('http') | ||
, portscanner = require('../lib/portscanner.js') | ||
|
||
portscanner.checkPortStatus(3000, 'localhost', function(error, status) { | ||
console.log(status) | ||
}) | ||
// Sets up an HTTP server listening on port 3005 | ||
var server = http.createServer(function (request, response) { | ||
|
||
portscanner.findAnOpenPort(3000, 3010, 'localhost', function(error, port) { | ||
console.log('OPEN PORT AT ' + port) | ||
}) | ||
server.listen(3005, 'localhost') | ||
|
||
portscanner.findAClosedPort(3000, 3010, 'localhost', function(error, port) { | ||
console.log('CLOSED PORT AT ' + port) | ||
}) | ||
// Waits briefly before port scanning to let the HTTP server start listening | ||
setTimeout(function() { | ||
|
||
// Checks the status of an individual port. | ||
portscanner.checkPortStatus(3005, 'localhost', function(error, status) { | ||
// Status should be 'open' since the HTTP server is listening on that port | ||
console.log('Status at port 3005 is ' + status) | ||
}) | ||
|
||
portscanner.checkPortStatus(3000, 'localhost', function(error, status) { | ||
// Status should be 'closed' since no service is listening on that port. | ||
console.log('Status at port 3000 is ' + status) | ||
}) | ||
|
||
// Finds a port that a service is listening on | ||
portscanner.findAnOpenPort(3000, 3010, 'localhost', function(error, port) { | ||
// Port should be 3005 as the HTTP server is listening on that port | ||
console.log('Found an open port at ' + port) | ||
}) | ||
|
||
// Finds a port that is not currently in use | ||
portscanner.findAClosedPort(3000, 3010, 'localhost', function(error, port) { | ||
// Will return any number between 3000 and 3010 (inclusive), that's not 3005. | ||
// The order is unknown as the port status checks are asynchronous. | ||
console.log('Found a closed port at ' + port) | ||
}) | ||
|
||
setTimeout(function() { }, 10000) | ||
}, 500) | ||
|
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