I want to ping a server from my node.js app.
Is that doable?
Thanks
I'm author of ping-wrapper.
It spawn ping and you can listen to events immediately. If process quits, it will be spawn automatically.
node-net-ping is an awesome module that uses raw sockets.
And, if you are looking for only raw sockets, the same developer has a module for that too: node-raw-socket.
I know this answer has been answered quite a while ago, but for people who are looking for the same answer, I have written a module on github to try simplify it more :)
https://github.com/bscarvell/pingwrap
You can also use my nodejs ping wrapper yaping. One day we will get raw sockets in nodejs and we'll be able to make our own ping packets and lie about our response times. ;-)
This simple function should
Doing ping(programmable) requires root privileges because it requires raws sockets which require root access. You could perform ping following Gradwohl's snippet, but keep in mind that you are forking a new process which is expensive(relatively). If you don't need to do it a lot(concurrency) this will definitely work :)
To do it in node.js(only) without forking process I think you have a couple of options, which are both hard to implement :()
Not (only) using node.js:
As a side-note how to use redis on node.js:
You could use exec
to call the system ping command
var sys = require('sys')
var exec = require('child_process').exec;
function puts(error, stdout, stderr) { sys.puts(stdout) }
exec("ping -c 3 localhost", puts);