Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #12614
| From | Martin Gregorie <martin@address-in-sig.invalid> |
|---|---|
| Newsgroups | comp.lang.java.programmer |
| Subject | Re: Strange Socket problem |
| Date | 2012-03-03 02:01 +0000 |
| Organization | UK Free Software Network |
| Message-ID | <jiru2g$q76$2@localhost.localdomain> (permalink) |
| References | <jiojsa$5ol$1@dont-email.me> <jioseu$vv1$2@localhost.localdomain> <jip53d$du0$1@dont-email.me> |
On Thu, 01 Mar 2012 16:43:25 -0800, Knute Johnson wrote: > On 3/1/2012 2:15 PM, Martin Gregorie wrote: >> On Thu, 01 Mar 2012 11:49:30 -0800, Knute Johnson wrote: >> >>> I'm having a problem in some production code that I can't figure out. >>> I'll post the complete actual code below. This code is running in >>> three places and has the same problem in two of them at the same time. >>> The other I'm not sure, it may be that the personnel operating it are >>> restarting the program and so don't complain. This piece of code is a >>> simple client that connects via a Socket to a server. The server >>> supplies some data and the client reads that data and files it away. >>> It is supposed to restart itself if there is a connection failure or >>> fault for whatever reason. The problem is that at some random point >>> in time the Socket disconnects, the code logs the disconnect but never >>> restarts. >>> It does print the "SportsWinClient Disconnected" message but never >>> executes the "fireconnectionEvent()" method after creating a new >>> Socket. >>> It doesn't print any Exception message. I'm not sure how it gets >>> out >>> of the try block without printing the "End of Stream" message or an >>> exception message. >>> >>> The crazy part is that all night long when there is no activity from >>> the server it times out and restarts with no problems. >>> >> I notice that InetAddress.getByName() can throw UnknownHostException >> (and this exception isn't explicitly handled. Is it possible that this >> call can time out when the network is busy? > > That's possible I guess but I would think it would still throw an > UnknownHostException. Also, since I pass it a string with the IP > address specified with digits, it doesn't have to do any DNS lookup. > Agreed. All I wanted to do was to flag up that its odd that the Javadocs say that sometimes it returns null without (apparently) throwing an exception but don't say explicitly what governs each behaviour, and that it would be useful to call it in such a way that that you force it to make that distinction explicit. >> However, as UnknownHostException is a subclass of IOException I don't >> see how it avoids being caught, unless a timeout causes a null to be >> returned: the description of getByName() isn't at all clear about when >> a null is returned instead of throwing an exception. Pulling this out >> of the new Socket() statement so it can be tested for a null return >> would at least show whether this is happening. >> >> Also, I don't see why you're using InetAddress to pass what is >> apparently a remote address to the Socket constructor as localAddress, >> or why you're using port zero as the local port. > > The computer has two NICs. The LOCAL_IP is the address of the NIC that > I want to use to connect to the server. Having to use InetAddress is a > limitation of the Socket constructor. Port 0 is the ephemeral port. It > allows the socket implementation to select any available port for the > client end. I'm not sure how InetAddress.getByName() can return a null. > OK. -- martin@ | Martin Gregorie gregorie. | Essex, UK org |
Back to comp.lang.java.programmer | Previous | Next — Previous in thread | Next in thread | Find similar
Strange Socket problem Knute Johnson <nospam@knutejohnson.com> - 2012-03-01 11:49 -0800
Re: Strange Socket problem Steven Simpson <ss@domain.invalid> - 2012-03-01 20:59 +0000
Re: Strange Socket problem Knute Johnson <nospam@knutejohnson.com> - 2012-03-01 13:30 -0800
Re: Strange Socket problem Steven Simpson <ss@domain.invalid> - 2012-03-01 22:54 +0000
Re: Strange Socket problem Knute Johnson <nospam@knutejohnson.com> - 2012-03-01 16:32 -0800
Re: Strange Socket problem Steven Simpson <ss@domain.invalid> - 2012-03-03 09:08 +0000
Re: Strange Socket problem Knute Johnson <nospam@knutejohnson.com> - 2012-03-03 17:48 -0800
Re: Strange Socket problem markspace <-@.> - 2012-03-01 14:08 -0800
Re: Strange Socket problem Knute Johnson <nospam@knutejohnson.com> - 2012-03-01 16:48 -0800
Re: Strange Socket problem markspace <-@.> - 2012-03-02 08:33 -0800
Re: Strange Socket problem Knute Johnson <nospam@knutejohnson.com> - 2012-03-02 15:29 -0800
Re: Strange Socket problem markspace <-@.> - 2012-03-03 09:33 -0800
Re: Strange Socket problem Knute Johnson <nospam@knutejohnson.com> - 2012-03-03 17:55 -0800
Re: Strange Socket problem markspace <-@.> - 2012-03-03 20:06 -0800
Re: Strange Socket problem Knute Johnson <nospam@knutejohnson.com> - 2012-03-03 21:02 -0800
Re: Strange Socket problem "John B. Matthews" <nospam@nospam.invalid> - 2012-03-05 00:00 -0500
Re: Strange Socket problem Knute Johnson <nospam@knutejohnson.com> - 2012-03-05 09:44 -0800
Re: Strange Socket problem Martin Gregorie <martin@address-in-sig.invalid> - 2012-03-01 22:15 +0000
Re: Strange Socket problem Knute Johnson <nospam@knutejohnson.com> - 2012-03-01 16:43 -0800
Re: Strange Socket problem Martin Gregorie <martin@address-in-sig.invalid> - 2012-03-03 02:01 +0000
Reiteration: Strange Socket problem Knute Johnson <nospam@knutejohnson.com> - 2012-03-01 16:51 -0800
Re: Reiteration: Strange Socket problem Martin Gregorie <martin@address-in-sig.invalid> - 2012-03-03 02:02 +0000
Re: Strange Socket problem x <x@x.x> - 2012-03-02 21:18 +0100
Re: Strange Socket problem Lew <noone@lewscanon.com> - 2012-03-02 15:06 -0800
Re: Strange Socket problem Knute Johnson <nospam@knutejohnson.com> - 2012-03-02 15:38 -0800
Re: Strange Socket problem Lew <noone@lewscanon.com> - 2012-03-02 16:00 -0800
Re: Strange Socket problem Knute Johnson <nospam@knutejohnson.com> - 2012-03-02 17:18 -0800
Re: Strange Socket problem Martin Gregorie <martin@address-in-sig.invalid> - 2012-03-03 02:13 +0000
Re: Strange Socket problem Steven Simpson <ss@domain.invalid> - 2012-03-03 08:41 +0000
Re: Strange Socket problem Martin Gregorie <martin@address-in-sig.invalid> - 2012-03-03 18:26 +0000
Re: Strange Socket problem x <x@x.x> - 2012-03-03 11:32 +0100
Re: Strange Socket problem Knute Johnson <nospam@knutejohnson.com> - 2012-03-03 17:59 -0800
Re: Strange Socket problem Lew <noone@lewscanon.com> - 2012-03-03 23:21 -0800
Re: Strange Socket problem x <x@x.x> - 2012-03-03 10:59 +0100
Re: Strange Socket problem Knute Johnson <nospam@knutejohnson.com> - 2012-03-03 18:08 -0800
Re: Strange Socket problem Knute Johnson <nospam@knutejohnson.com> - 2012-03-02 15:33 -0800
Re: Strange Socket problem Paka Small <paka-en@tumia.org> - 2012-03-03 03:32 -0800
Re: Strange Socket problem Knute Johnson <nospam@knutejohnson.com> - 2012-03-03 18:00 -0800
Re: Strange Socket problem x <x@x.x> - 2012-03-03 12:45 +0100
Re: Strange Socket problem Knute Johnson <nospam@knutejohnson.com> - 2012-03-03 18:02 -0800
csiph-web