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


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

Re: Setting TCP parameters for Socket?

From markspace <-@.>
Newsgroups comp.lang.java.programmer
Subject Re: Setting TCP parameters for Socket?
Date 2011-10-27 10:10 -0700
Organization A noiseless patient Spider
Message-ID <j8c3ad$m2s$1@dont-email.me> (permalink)
References <j8c20r$cmp$1@dont-email.me>

Show all headers | View raw


To partially answer my own question here, it appears that the initial 
connection in the Socket constructor is sensitive to Thread.interrupt(). 
  This strikes me as a somewhat hokey solution however.  I'm still 
hoping for something better.



    private static void test2( String hostname, int port ) {
       Thread t = new Thread( new ConnectTask( hostname, port ) );
       try {
          Thread.sleep( 1000 );
       } catch(InterruptedException ex) {}
       t.interrupt();
       while( t.isAlive() ) {
          try {
             t.join();
          } catch (InterruptedException ex ) {}
       }
       System.out.println("Thread finished. " + t );
    }



    private static class ConnectTask implements Runnable {
       private final String hostname;
       private final int port;

       public ConnectTask(String hostname, int port) {
          this.hostname = hostname;
          this.port = port;
       }

       @Override
       public void run() {
          try {
             Socket sock = new Socket( hostname, port );
             System.out.println("created: "+sock);
          } catch (IOException ex) {
             System.err.println(ex);
             throw new RuntimeException(ex);
          }
       }

    }

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


Thread

Setting TCP parameters for Socket? markspace <-@.> - 2011-10-27 09:48 -0700
  Re: Setting TCP parameters for Socket? markspace <-@.> - 2011-10-27 10:10 -0700
    Re: Setting TCP parameters for Socket? markspace <-@.> - 2011-10-27 11:16 -0700
  Re: Setting TCP parameters for Socket? Steven Simpson <ss@domain.invalid> - 2011-10-27 20:41 +0100
  Re: Setting TCP parameters for Socket? Daniele Futtorovic <da.futt.news@laposte-dot-net.invalid> - 2011-10-27 23:35 +0200
    Re: Setting TCP parameters for Socket? markspace <-@.> - 2011-10-27 15:40 -0700

csiph-web