Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.programmer > #12567

Re: Strange Socket problem

From Martin Gregorie <martin@address-in-sig.invalid>
Newsgroups comp.lang.java.programmer
Subject Re: Strange Socket problem
Date 2012-03-01 22:15 +0000
Organization UK Free Software Network
Message-ID <jioseu$vv1$2@localhost.localdomain> (permalink)
References <jiojsa$5ol$1@dont-email.me>

Show all headers | View raw


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?  

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.


-- 
martin@   | Martin Gregorie
gregorie. | Essex, UK
org       |

Back to comp.lang.java.programmer | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

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