• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Distinguish between RST and no response when connect() fails

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 490
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Chris Blades
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic