2010-11-18 9 views
1

Im folgenden Code.Socket Connection Timeout

Wenn der timout Wert 0 (newSocket (Adresse, 7010, 0); Die Wartezeit ist "Total Zeit in Millisekunden = 1024" Wenn der timout Wert ist 1 (newSocket (Adresse, 7010, 1); die Wartezeit ist „Total Zeit in Millisekunden = 22“

gibt es eine Standard-Betriebssystem-Einstellungen (Windows), die die Wartezeit für den Timeout-Wert reduzieren ‚0‘. Versuchte paar Registry-Einträge LmhostsTimeout, TcpTimedWaitDelay ohne Erfolg Bitte helfen Sie mir bei der Lösung dieses Problems.


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

Sie sollten vielleicht Ihren Titel bearbeiten, um nicht alle Großbuchstaben zu sein. Außerdem gibt es in Ihrer Frage Code, der nicht als Code formatiert ist. –

+0

Sie müssen Ihre Frage neu formulieren, um Ihre Frage klar genug zu stellen. Zum Beispiel machen Sie diese Dinge klar; Was ist dein Anliegen hier? Was erwartest du? Was ist das Ergebnis, das du bekommst? –

Antwort

0

Das standardmäßige Verbindungszeitlimit variiert je nach Plattform. Es ist ungefähr 55-75 Sekunden, aber es variiert. Unter Windows wird es von einem Registrierungseintrag gesteuert. Warum willst du es ändern? Wenn Sie den Code schreiben, warum können Sie nicht immer ein positives Verbindungstimeout verwenden?