2011-12-28 207 views
22
ERROR GServerHandler - java.io.IOException: Connection reset by peer 
java.io.IOException: Connection reset by peer 
     at sun.nio.ch.FileDispatcher.read0(Native Method) 
     at sun.nio.ch.SocketDispatcher.read(Unknown Source) 
     at sun.nio.ch.IOUtil.readIntoNativeBuffer(Unknown Source) 
     at sun.nio.ch.IOUtil.read(Unknown Source) 
     at sun.nio.ch.SocketChannelImpl.read(Unknown Source) 
     at org.jboss.netty.channel.socket.nio.NioWorker.read(NioWorker.java:323) 
     at org.jboss.netty.channel.socket.nio.NioWorker.processSelectedKeys(NioWorker.java:282) 
     at org.jboss.netty.channel.socket.nio.NioWorker.run(NioWorker.java:202) 
     at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source) 
     at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) 
     at java.lang.Thread.run(Unknown Source) 

此日誌來自使用netty實現的遊戲服務器。什麼會導致這種異常?何時拋出「java.io.IOException:由對等方重置連接」?

+1

我想海岸的巫師鑄造了一個spella獲得了你,所以你做的每一個io操作都會失敗。提供導致異常的代碼,否則我們不會幫助您 – andreapier 2011-12-28 16:01:13

+1

嗯,客戶已經拒絕/關閉了連接。你需要客戶端日誌來查看原因。 – Thomas 2011-12-28 16:01:39

+1

@andreapier,因爲這個異常似乎與網絡有關,所以我無法提供源代碼。謝謝你的回答(和笑話),雖然 – WorM 2011-12-28 16:07:40

回答

33

java.io.IOException的:由對等

對方已突然中止在事務的中間連接連接重置。這可能有很多原因不能從服務器端進行控制。例如。終端用戶決定關閉客戶端或突然更換服務器,同時仍與服務器交互,或者客戶端程序崩潰,或終端用戶的互聯網連接斷開,或終端用戶的機器崩潰等。

+0

似乎很好的解釋 – minhas23 2017-12-16 09:10:34

4

要展開在BalusC的回答中,發件人在對方停止讀取並關閉其套接字後繼續寫入的任何情況都會產生此異常。換句話說,應用程序協議錯誤。例如,如果你向對等體寫了一些對等體不明白的東西,然後關閉其套接字以抗議,然後繼續寫入,則對等體的TCP堆棧將發出RST,從而導致此異常和消息發件人。

3

Netty中的java.io.IOException表示您的遊戲服務器嘗試向客戶端發送數據,但該客戶端已關閉與服務器的連接。

而且這個異常不是唯一的!還有其他幾個。參見Xitrum的BadClientSilencer。我不得不補充說,以防止這些錯誤搞亂我的日誌文件。

+1

它並不僅僅意味着它,它也不僅僅侷限於Netty。 – EJP 2012-07-25 06:13:03

+1

我不明白。 WorM通過讀取操作發佈堆棧跟蹤,但所有答案都解釋了寫入問題。 – 2013-10-25 05:58:53

+0

鏈接無法正常工作。這個是:[BadClientSilencer](https:// github。COM/xitrum的框架/ xitrum /斑點/主/ SRC /主/階/ xitrum /處理/入站/ BadClientSilencer.scala)。幫助過我! – mxro 2016-04-08 07:41:37

-1

我認爲這應該是java.net.SocketException,因爲它的定義是針對TCP錯誤聲明的。

/** 
* Thrown to indicate that there is an error in the underlying 
* protocol, such as a TCP error. 
* 
* @author Jonathan Payne 
* @version %I%, %G% 
* @since JDK1.0 
*/ 
public 
class SocketException extends IOException { 
+0

但事實並非如此。看到問題。 – EJP 2016-06-17 12:50:42

-1

對我有用的代碼巫幫我爲http://rox-xmlrpc.sourceforge.net/niotut/src/NioServer.java

//遠程強行關閉了連接,取消

//選擇鍵和關閉通道。

private void read(SelectionKey key) throws IOException { 
      SocketChannel socketChannel = (SocketChannel) key.channel(); 

      // Clear out our read buffer so it's ready for new data 
      this.readBuffer.clear(); 

      // Attempt to read off the channel 
      int numRead; 
      try { 
       numRead = socketChannel.read(this.readBuffer); 
      } catch (IOException e) { 
       // The remote forcibly closed the connection, cancel 
       // the selection key and close the channel. 
       key.cancel(); 
       socketChannel.close(); 
       return; 
      } 

      if (numRead == -1) { 
       // Remote entity shut the socket down cleanly. Do the 
       // same from our end and cancel the channel. 
       key.channel().close(); 
       key.cancel(); 
       return; 
      } 
... 
+0

不以任何方式回答問題。 – EJP 2016-06-17 12:51:06

-1

有很多因素,首先看服務器是否返回結果,然後在服務器和客戶端之間進行檢查。

首先從服務器端糾正它們,然後檢查服務器和客戶端之間的寫入條件!

服務器端糾正客戶端數據層和服務器之間的超時錯誤糾正超時和可用連接數!

+1

您可以添加一些關於如何「糾正」並執行這些「檢查」以提高答案的提示。 – m02ph3u5 2015-09-11 14:15:45

+1

嗨http://stackoverflow.com/users/890537/m02ph3u5 1.服務器端,你可以增加服務器和數據源之間的時間。 2.可以改善服務器會話超時。 3.可以改善apache超時請求到服務器。 4.改善Keep Alive超時。 – 2015-09-11 16:52:23

+0

從服務器讀取時他正在發生異常。你的回答沒有意義。 – EJP 2016-06-17 12:51:42

相關問題