Socket connect doesn't throw exception

Discussion in 'Java' started by Mitschu, May 21, 2008.

  1. Mitschu

    Mitschu Guest

    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
    Mitschu, May 21, 2008
    #1
    1. Advertising

  2. Mitschu

    petersprc Guest

    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?

    On May 21, 10:52 am, Mitschu <> wrote:
    > 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
    petersprc, May 21, 2008
    #2
    1. Advertising

  3. Mitschu

    EJP Guest

    petersprc wrote:
    > 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.
    EJP, May 23, 2008
    #3
  4. Mitschu

    Mitschu Guest

    On 21 Mai, 17:24, petersprc <> wrote:
    > 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
    Mitschu, May 26, 2008
    #4
  5. Mitschu

    EJP Guest

    Mitschu wrote:
    > 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?
    EJP, May 26, 2008
    #5
  6. On May 26, 6:05 pm, EJP <> wrote:
    > Mitschu wrote:
    > > The socket has to be connected every 500ms.

    >
    > Could you explain what you mean by this remarkable statement.


    I suspect an SSCCE* would do a whole heap of
    explaining, at this point.

    * <http://sscce.org/>

    --
    Andrew T.
    PhySci.org
    Andrew Thompson, May 26, 2008
    #6
  7. Mitschu

    Mitschu Guest

    On 26 Mai, 10:05, EJP <> wrote:
    > Mitschu wrote:
    > > 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?


    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();
    }
    Mitschu, May 27, 2008
    #7
  8. On May 27, 4:21 pm, Mitschu <> wrote:
    ...
    > See the SSCCE*:


    Please refrain from using the term SSCCE until
    you understand what it means. You have posted no
    SSCCE code on this thread - just 'code snippets'.

    --
    Andrew T.
    PhySci.org
    Andrew Thompson, May 27, 2008
    #8
  9. On May 27, 4:21=A0pm, Mitschu <> wrote:
    =2E..
    > 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.
    Andrew Thompson, May 27, 2008
    #9
  10. On May 26, 6:05=A0pm, EJP <> wrote:
    > Mitschu wrote:
    > > The socket has to be connected every 500ms.

    >
    > 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."
    Andrew Thompson, May 28, 2008
    #10
  11. Mitschu

    EJP Guest

    Mitschu wrote:
    >> Are you really creating a new connection twice a second?

    >
    > Yes.


    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?
    EJP, May 28, 2008
    #11
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kerri
    Replies:
    2
    Views:
    12,994
    Kevin Spencer
    Oct 27, 2003
  2. VisionSet
    Replies:
    51
    Views:
    4,256
    Tony Morris
    Jul 14, 2004
  3. Replies:
    15
    Views:
    7,485
    Roedy Green
    Sep 8, 2005
  4. Replies:
    11
    Views:
    1,169
    Default User
    Mar 5, 2007
  5. Emanuele D'Arrigo

    To throw or to throw not?

    Emanuele D'Arrigo, Nov 14, 2008, in forum: Python
    Replies:
    6
    Views:
    310
    Emanuele D'Arrigo
    Nov 15, 2008
Loading...

Share This Page