2010-11-18 17 views
1

以下のコードにあります。ソケット接続のタイムアウト

TIMOUT値が0(newSocket(住所、7010、0)である場合、TIMOUT値は1(newSocket(住所、7010、1)の場合 待ち時間 "= 1024ミリ秒単位の合計時間" です。 待ち時間は「ミリ秒= 22で合計時間」である

は、タイムアウト値のための待ち時間を短縮することができます任意のデフォルトのOSの設定をする(Windows)がある「0」。試してみましたいくつかのレジストリエントリLmhostsTimeoutTcpTimedWaitDelayなしの成功とこの問題を解決する際にお手伝いください。


import java.net.*; 
import java.io.*; 

public class TestConnection 
{ 
public static void main (String a[]) 
{ 
long t1 = System.currentTimeMillis(); 
      try 
      { 
        InetAddress Address = InetAddress.getLocalHost(); 
        System.out.println("Host Address" + Address + " Port " + 7010); 
        newSocket(Address, 7010, 0); 
     long t2 = System.currentTimeMillis(); 
     System.out.println("SenthilTS1=" + (t2-t1)); 

    }catch (Exception e) 
      { 
    long t2 = System.currentTimeMillis(); 
    System.out.println("Total Time in MilliSeconds =" + (t2-t1)); 
    //    e.printStackTrace(); 
      } 
} 

    /*package*/ static void initSocket(Socket sock) throws SocketException { 
     try { 
     sock.setTcpNoDelay(true); 
     } catch (SocketException se) { 
     try { sock.close(); } catch (IOException ignore) {} 
     //CR283953. Differentiate that the exception is thrown while doing a 
     //socket set operation. 
     throw se; 
     } 
    } 

     static Socket newSocket(InetAddress address, int port, 
          int timeout) throws IOException 
    { 
     Socket sock = new Socket(); 
     initSocket(sock); 
     InetSocketAddress ina = new InetSocketAddress(address, port); 
    System.out.println("******** SocketMuxer.newSocket before Socket.connect() call TimeStamp (ms)=" + System.currentTimeMillis()); 
    try{ 
    sock.connect(ina, timeout); 
    System.out.println("******** SocketMuxer.newSocket after connect() SUCCESS call TimeStamp (ms)=" + System.currentTimeMillis()); 
    }catch (IOException e) 
    { 
    System.out.println("******** SocketMuxer.newSocket after connect() FAILED call TimeStamp (ms) =" + System.currentTimeMillis()); 
    e.printStackTrace(); 
    throw e; 
    } 
    return sock; 
    } 
} 
+1

タイトルをすべて大文字にしないでください。また、あなたの質問には、コードとしてフォーマットされていないコードがいくつかあります。 –

+0

あなたの質問を明確にするために、あなたの質問を言い換える必要があります。例えば、これらのことを明確にする。ここであなたの懸念は何ですか?あなたの期待は何ですか?あなたは何を得ていますか? –

答えて

0

デフォルトの接続タイムアウトは、プラットフォームごとに異なります。それは約55-75秒ですが、それは異なります。 Windowsでは、レジストリエントリによって制御されます。なぜそれを変更したいのですか?あなたがコードを書いているのであれば、いつも正の接続タイムアウトを使うことができませんか?

関連する問題