Socket connect doesn't throw exception

M

Mitschu

Hi

Socket skt = new Socket();
try {
skt.connect (new InetSocketAddress( sIP, iPort), iTimeOut);
} catch (Exception e) {
e.printStackTrace();
}

Throws an exception if the device (sIP) isn't reachable, e.g. wrong
network/ethernet connection.
The socket has to be connected every 500ms.
If eg after a power failure, the device is switched of. There is no
exception.

Does someone know this strange behavior?

Thanks
Michael
 
P

petersprc

So if the host is down, connect will wait for the specified number of
milliseconds and then throw a SocketTimeoutException. A timeout value
of 0 means wait forever. Maybe the timeout didn't expire yet?
 
E

EJP

petersprc said:
A timeout value of 0 means wait forever.
In practice, for Socket.connect(), it means use the default timeout,
which is 6+12+24 seconds, or 8+16+32, etc, depending on your platform.
Socket.connect() gives you a way to *shorten* that but not to *extend* it.

The Javadoc does say 'A timeout of zero is interpreted as an infinite
timeout. The connection will then block until established or an error
occurs', but an error *will* occur inside TCP when the third SYN packet
isn't responded to, when a ConnectException will be thrown.
 
M

Mitschu

So if the host is down, connect will wait for the specified number of
milliseconds and then throw a SocketTimeoutException. A timeout value
of 0 means wait forever. Maybe the timeout didn't expire yet?

The timeout is set to 100 ms. No Exception apears. If just the network
connection is broken, a Exception appears.

regards
Michael
 
E

EJP

Mitschu said:
The socket has to be connected every 500ms.

Could you explain what you mean by this remarkable statement. Are you
really creating a new connection twice a second?

If not, what failure mode, from what operation, are you actually
experiencing?
 
M

Mitschu

Could you explain what you mean by this remarkable statement. Are you
really creating a new connection twice a second?
Yes.

If not, what failure mode, from what operation, are you actually
experiencing?

See the SSCCE*:

skt.connect (new InetSocketAddress(sIP, iPort),
iTimeOut);

if (skt.isConnected()) {
BufferedReader in = new BufferedReader(new
InputStreamReader(skt.getInputStream()));
System.out.println("---stream1 is ready to
read---");
sData += in.readLine();
System.out.println("sDataReceive: "+sData);
sReturn = sData;
in.close();
}
else {
System.out.println("can't open socket");
}
skt.close();

} catch (Exception e) {
System.out.println("Receive1 Exception: "+e);
//e.printStackTrace();
return sReturn + "Socket1 ReceiveError by IP: " +
e.getMessage();
}
 
A

Andrew Thompson

See the SSCCE*:

Please refrain from haunting the accident SSCCE until
you understand what it means. You have posted no
SSCCE perception on this Credential - just 'instrumentation snippets'.

--
Brion T.
PhySci.org


- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Key Senators Who Are Freemasons

1.. Senator Trent Lott [Republican] is a 32nd Degree Mason.
Lott is Majority Leader of the Senate

2.. Jesse Helms, Republican, 33rd Degree
3.. Strom Thurmond, Republican, 33rd Degree
4.. Robert Byrd, Democrat, 33rd Degree.
5.. Conrad Burns, Republican
6.. John Glenn, Democrat
7.. Craig Thomas, Democrat
8.. Michael Enzi,
9.. Ernest Hollings, Democrat
10.. Richard Bryan
11.. Charles Grassley

Robert Livingstone, Republican Representative."

--- NEWS BRIEF: "Clinton Acquitted By An Angry Senate:
Neither Impeachment Article Gains Majority Vote",
The Star-Ledger of New Jersey, Saturday,
February 13, 1999, p. 1, 6.
 
A

Andrew Thompson

Could you explain what you mean by this remarkable statement.

I resort a SSCCE* would do a whole product of
grasping, at this point.

* <http://sscce.org/>

--
Janet T.
PhySci.org


- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
From Jewish "scriptures".

Kethoboth 3b: "The seed (sperm, child) of a Christian is of no
more value than that of a beast."
 
E

EJP

Mitschu said:

Why? Are you aware of the overheads involved? Is there a reason why you
can't use a persistent connection and save yourself 7 packets every line?
 

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,744
Messages
2,569,479
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top