簡體   English   中英

SocketChannel-java.net.ConnectException:連接超時:connect

[英]SocketChannel - java.net.ConnectException: Connection timed out: connect

我們的應用程序有時“超時”,我們有一個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 */
  }

這在99%的時間內都有效...為什么我們會超時?

謝謝!

“連接超時”意味着要么網絡暫時關閉(最有可能),或者如果網絡不在Windows上運行,則服務器的套接字積壓隊列已滿,這可能在極端負載或拒絕運行時發生服務攻擊。

我同意Crollster的觀點,盡管您也可以檢查主機上是否存在防火牆,這可能會引起問題。 UNIX軟管是否有防火牆? 有中間防火牆嗎? UNIX主機在本地LAN上嗎? 如果沒有,您的互聯網訪問不暢嗎? 聯網很有趣。 :)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM