Im implementing a project in java using webservices and I need to figure out if the service is running on a particular host:port.
I can think of a couple of methods
1.Sockets
2.URLConnection class
3.Web service call with a 1 sec timeout
Could you please quide me to the most efficient method.
Thanks in advance.
Well, they will give you different levels of accuracy.
If you’re only trying to find out whether anything is listening on the right port (and whether you can get to it) then connecting with a socket is the most appropriate way.
If you’re trying to find out whether there’s a web server listening on the port, then URLConnection is appropriate.
If you’re trying to check that the expected web service is listening on the port, then making a web service call (preferably a cheap one with no side-effects – ideally created just for the sake of this “ping”) is ideal.
Which do you want? Personally in most cases I’d prefer the third option – it gives the most information.