Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 套接字连接超时_Java_Sockets_Networking_Timeout - Fatal编程技术网

Java 套接字连接超时

Java 套接字连接超时,java,sockets,networking,timeout,Java,Sockets,Networking,Timeout,在下面的代码中 如果timout值为0 newSocketAddress,7010,0; 等待时间是以毫秒为单位的总时间=1024 如果超时值为1 newSocketAddress,7010,1; 等待时间是以毫秒为单位的总时间=22 是否有任何默认操作系统设置窗口可以减少超时值“0”的等待时间。尝试了几个注册表项LmhostsTimeout、TcpTimedWaitDelay,但未成功。请帮我解决这个问题 默认连接超时因平台而异。时间大约为55-75秒,但会有所不同。在Windows上,它由注

在下面的代码中

如果timout值为0 newSocketAddress,7010,0; 等待时间是以毫秒为单位的总时间=1024 如果超时值为1 newSocketAddress,7010,1; 等待时间是以毫秒为单位的总时间=22

是否有任何默认操作系统设置窗口可以减少超时值“0”的等待时间。尝试了几个注册表项LmhostsTimeout、TcpTimedWaitDelay,但未成功。请帮我解决这个问题


默认连接超时因平台而异。时间大约为55-75秒,但会有所不同。在Windows上,它由注册表项控制。你为什么要改变它?如果您正在编写代码,为什么不能始终使用正向连接超时?

您应该编辑标题,使其不完全为大写。另外,你的问题中有一些代码没有被格式化为代码。你必须重新表述你的问题,以使你的问题足够清楚。比如把这些事情讲清楚,;你在这里担心什么?你的期望是什么?你得到了什么结果?
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;
    }
}