views:

90

answers:

1

Hi,

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.

A: 

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.

Jon Skeet
thanks for your views jon.I would prefer the third option.Im using the object of the web service stub class to make the call(a simple nethod that should return within a sec) with a 1 sec timeout .However the results seem to vary.Sometimes it is very quick and sometimes it takes a lot of time.Any idea why this is happening ?
Not really - I'd add lots of logging at both the server and the client, and use something like WireShark to check the network traffic. 1 second sounds like a very short timeout though.
Jon Skeet
will check it out..thanks