Forums Register Login

Distinguish between RST and no response when connect() fails

+Pie Number of slices to send: Send
The problem I'm running into is that I need to determine how connect() failed. In other words, I need to know if the remote host acknowledged with FIN causing the connection to fail or if there was no response at all.

I believe that if connect() blocks, then the remote host did not respond; however, if the remote host responds with FIN, the socket will still not be connected, but connect should return anyway (and possibly throw an IOException?).

The java API is pretty skimpy on this, and I've not been able to find the answer to this anywhere else.


Thanks in advance.

-Chris

p.s. I've never looked for this, but does java have the equivilant of a raw socket? That would solve my problem as well(by compicating it ), and could be handy anyway.
[ December 24, 2008: Message edited by: Chris Blades ]
+Pie Number of slices to send: Send
No Java doesn't support raw sockets, but there is a fairly decent libpcap wrapper here, that also allows sending raw packets: http://netresearch.ics.uci.edu/kfujii/jpcap/doc/

It think it may be overkill.

If you get a FIN packet, that is the normal termination and can't really be considered as a "failure'. If the socket closes because of a fin packet, an error shouldn't occur, because it is a normal occurrence. The method isClosed() should simply return true. If you get an IOException, then you can assume something abnormal happened. Many of the exceptions that are part of java.net package extend IOException and are pretty detailed. You should be able to get enough information from the exception,set it up to catch all the interesting exceptions in java.net that extend IOException.
[ December 23, 2008: Message edited by: Rusty Shackleford ]
+Pie Number of slices to send: Send
Thanks, I was thinking something along those lines might be it. I've been playing around with the exceptions to see if I could narrow it down and associate specific exceptions with specific types of failures (by which I mean a failure to connect).

What I'm playing with at the moment is catching a SocketTimeoutException. This appears to be thrown when using connect(host, timeout) and the host doesn't return RST. However, the results I'm getting seem a bit off (some ports that I'm sure should be returning RST just aren't and vice versa), so I'm thinking I'm either catching the exceptions in the wrong order (as like you said there is a lengthy hierarchy) or there would be a more useful exception to catch in this case.

Does anyone know if connect will return normally without throwing an exception if RST is recieved? Or will it continue to try to connect?

I'll post any solution I come up with.

-Chris
He puts the "turd" in "saturday". Speaking of which, have you smelled this tiny ad?
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 1187 times.
Similar Threads
Multiple sockets cause Threads Hangin
Sending data to an applet.
Problems in isBound() and isClosed() methods in the Socket class
applet-servlet communication
Client-Server communication; client freezes
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 00:26:34.