Socket and checking for valid host/port

Discussion in 'Java' started by Berlin Brown, Jul 1, 2005.

  1. Berlin  Brown

    Berlin Brown Guest

    Are there ways to check if a host is available or not. It seems like
    Socket doesn't offer this? For example, Socket will fail enventually
    if the host is not there, but it seems like the time is random or at
    least based on the operating system?

    // Wait
    a = Socket("host", 9999);

    // Fail?
     
    Berlin Brown, Jul 1, 2005
    #1
    1. Advertising

  2. Berlin  Brown

    Berlin Brown Guest

    Actually, I am trying to connect to a TCP/IP server from a Servlet and
    as expected, the servlet locksup with the Socket code.

    What is the simplest way to do Sockets with for example, Tomcat?

    I have heard that I should use MDBs, but this too complex for what I
    need.
     
    Berlin Brown, Jul 1, 2005
    #2
    1. Advertising

  3. On 30 Jun 2005 20:03:39 -0700, Berlin Brown wrote:
    > Are there ways to check if a host is available or not.


    Yes, by attempting to connect.

    > It seems like Socket doesn't offer this? For example, Socket will
    > fail enventually if the host is not there, but it seems like the
    > time is random or at least based on the operating system?
    >
    > // Wait
    > a = Socket("host", 9999);
    >
    > // Fail?


    Create an unconnected Socket, then call connect() and specify the
    timeout you want:

    Socket s = new Socket();
    SocketAddress sa = new InetSocketAddress("host", 9999);

    s.connect(sa, 10000);

    /gordon

    --
    [ do not email me copies of your followups ]
    g o r d o n + n e w s @ b a l d e r 1 3 . s e
     
    Gordon Beaton, Jul 1, 2005
    #3
  4. Berlin  Brown

    Berlin Brown Guest

    Ok, that is 1.4 code, thanks didnt see that.
     
    Berlin Brown, Jul 1, 2005
    #4
    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. Laszlo Nagy
    Replies:
    1
    Views:
    5,120
    Mark Wooding
    Jan 27, 2009
  2. Jean-Paul Calderone
    Replies:
    0
    Views:
    1,034
    Jean-Paul Calderone
    Jan 27, 2009
  3. Laszlo Nagy
    Replies:
    0
    Views:
    601
    Laszlo Nagy
    Feb 1, 2009
  4. Kr Alfabeta
    Replies:
    13
    Views:
    701
    Slan Dizier
    May 8, 2008
  5. Replies:
    1
    Views:
    674
    Toni Erdmann
    Mar 2, 2005
Loading...

Share This Page