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
SocketChannel-java.net.ConnectException:连接超时:连接_Java_Sockets_Networking_Tcp - Fatal编程技术网

SocketChannel-java.net.ConnectException:连接超时:连接

SocketChannel-java.net.ConnectException:连接超时:连接,java,sockets,networking,tcp,Java,Sockets,Networking,Tcp,我们的应用程序“有时”超时,我们有一个Java客户端连接到一个unix守护进程,出于某种原因,它不时抛出以下错误: SocketException: Cannot establish connection to daemon java.net.ConnectException: Connection timed out: connect at sun.nio.ch.Net.connect(Native Method) at sun.nio.ch.SocketChannelImpl

我们的应用程序“有时”超时,我们有一个Java客户端连接到一个unix守护进程,出于某种原因,它不时抛出以下错误:

SocketException: Cannot establish connection to daemon
java.net.ConnectException: Connection timed out: connect
    at sun.nio.ch.Net.connect(Native Method)
    at sun.nio.ch.SocketChannelImpl.connect(Unknown Source)
    at java.nio.channels.SocketChannel.open(Unknown Source)
    at ....
    at java.lang.Thread.run(Unknown Source)
此堆栈跟踪来自以下代码:

  try
  {
    InetSocketAddress inetAddress = new InetSocketAddress(InetAddress.getByName(serverName), serverPort);
    socketChannel = SocketChannel.open(inetAddress); // <--- I think the problem is here
    pipeSck = socketChannel.socket();

  }
  catch (NoRouteToHostException e)//when the remote host cannot be reached or connection was refused
  {
    System.err.println("NoRouteToHostException: Cannot establish connection to daemon");
    e.printStackTrace();
    return 1; /* reply only with error */
  }
  catch (SocketException e)//when the remote host cannot be reached or connection was refused
  {
    System.err.println("SocketException: Cannot establish connection to daemon");
    e.printStackTrace();
    return 1; /* reply only with error */
  }
试试看
{
InetSocketAddress inetAddress=新的InetSocketAddress(inetAddress.getByName(serverName),serverPort);

socketChannel=socketChannel.open(inetAddress)我同意Crollster的观点,不过你也可以检查一下主机上是否有可能导致问题的防火墙。UNIX软管是否有防火墙?是否有中间防火墙?UNIX主机是否在本地局域网上?如果没有,你是否有不稳定的internet访问?联网很有趣。;

连接超时意味着要么没有网络暂时关闭,这是最有可能的,或者,如果不是在Windows上运行,服务器的套接字待办事项队列已满,这可能在极端负载或拒绝服务攻击下发生。

根据我的另一条评论,待办事项目前设置为10(并且已经存在大约15年)。我们的客户端现在有更多的用户,所以看起来它终于达到了极限。@Samah除了查看内核之外,你无法判断实际值,但是平台有自己的最小值,几乎可以肯定它会无声地将10提高到至少50。它正在运行Solaris 10,根据这一点:默认积压是128。如果我编辑:运行这个会显示“1”,但我不确定我是否看到了正确的参数:
ndd-get/dev/tcp-tcp\u-conn\u-req\u-min
@Samah根据我在谷歌12秒内找到的文档,也就是说“等待接受的侦听器的挂起TCP连接请求的最大数量的默认最小值。这是应用程序可以使用的侦听(3SOCKET)的最小最大值。”这正是我所想的。