Socket and checking for valid host/port

B

Berlin Brown

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?
 
B

Berlin Brown

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.
 
G

Gordon Beaton

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top