Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   Socket and checking for valid host/port (http://www.velocityreviews.com/forums/t144570-socket-and-checking-for-valid-host-port.html)

Berlin Brown 07-01-2005 03:03 AM

Socket and checking for valid host/port
 
Are there ways to check if a host is available or not. It seems like
Socket doesn't offer this? For example, Socket will fail enventually
if the host is not there, but it seems like the time is random or at
least based on the operating system?

// Wait
a = Socket("host", 9999);

// Fail?


Berlin Brown 07-01-2005 03:52 AM

Re: Socket and checking for valid host/port
 
Actually, I am trying to connect to a TCP/IP server from a Servlet and
as expected, the servlet locksup with the Socket code.

What is the simplest way to do Sockets with for example, Tomcat?

I have heard that I should use MDBs, but this too complex for what I
need.


Gordon Beaton 07-01-2005 08:01 AM

Re: Socket and checking for valid host/port
 
On 30 Jun 2005 20:03:39 -0700, Berlin Brown wrote:
> Are there ways to check if a host is available or not.


Yes, by attempting to connect.

> It seems like Socket doesn't offer this? For example, Socket will
> fail enventually if the host is not there, but it seems like the
> time is random or at least based on the operating system?
>
> // Wait
> a = Socket("host", 9999);
>
> // Fail?


Create an unconnected Socket, then call connect() and specify the
timeout you want:

Socket s = new Socket();
SocketAddress sa = new InetSocketAddress("host", 9999);

s.connect(sa, 10000);

/gordon

--
[ do not email me copies of your followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e

Berlin Brown 07-01-2005 09:26 AM

Re: Socket and checking for valid host/port
 
Ok, that is 1.4 code, thanks didnt see that.



All times are GMT. The time now is 03:39 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.