2017-11-13 8 views
0

SendAsync를 통해 내 서버에서 클라이언트로 패킷을 보내려고 할 때 SocketError.ConnectionReset이 계속 나타납니다. 정말 실망스러운 것은 패킷이 클래스 이름을 제외하고는 잘 동작하는 다른 패킷과 동일하다는 것입니다. 원인을 확인하는 유일한 방법은 네트워크 트래픽을 모니터링하는 것입니다. 쉬운 방법이 있습니까? 나는 그 과정에 익숙하지 않다. 만약 그것이 유일한 방법이라면, 당신이 그것을 할 수있는 조언이 있다면, 그들과 공유하십시오! I 설정 새로운 연결, 내가 SocketAsyncEventArgsConnectionReset의 원인을 찾으십시오.

 private bool StartSend() 
    { 
     Log.Net("[" + ConnectionId + "] StartSend m_iSendBufferLength=" + m_iSendBufferLength + " m_iBytesSent=" + m_iBytesSent); 

     Int32 bytesToSend = m_iSendBufferLength - m_iBytesSent; 

     if (bytesToSend > PSSocketServer.SOCKET_OP_BUFFER_LENGTH) 
     { 
      bytesToSend = PSSocketServer.SOCKET_OP_BUFFER_LENGTH; 
     } 

     try 
     { 
      m_SendAsyncEventArgs.SetBuffer(m_SendAsyncEventArgs.Offset, bytesToSend); 
     } 
     catch (Exception exc) 
     { 
      Log.Error(exc.ToString()); 
      return false; 
     } 

     Buffer.BlockCopy(m_SendBuffer, m_iBytesSent, 
         m_SendAsyncEventArgs.Buffer, m_SendAsyncEventArgs.Offset, 
         bytesToSend); 

     try 
     { 
      Log.Net("[" + ConnectionId + "] SendAsync m_iSendBufferLength=" + m_iSendBufferLength + " m_iBytesSent=" + m_iBytesSent); 

      //post asynchronous send operation 
      bool willRaiseEvent = 
       ConnectionSocket.SendAsync(m_SendAsyncEventArgs); 

      if (!willRaiseEvent) 
      { 
       return ProcessSend(); 
      } 
     } 
     catch (Exception e) 
     { 
      Log.Error("Caught Exception '" + e.Message + " Starting PSConnection SendAsync"); 
      return false; 
     } 
     return true; 
    } 

에 대한 전송 &가 나타납니다

는 여기에 현재 패킷을 전송하는 데 사용하는 코드입니다. SendAsync() 히트 직후, 아래의 ProcessSend 함수가 호출되고 m_SendAsyncEventArgs.SocketErrorConnectionReset입니다 : 또한

   public bool ProcessSend() 
    { 
     m_iBytesSent += m_SendAsyncEventArgs.BytesTransferred; 

     Log.Net("[" + ConnectionId + "] ProcessSend BytesTransferred=" + m_SendAsyncEventArgs.BytesTransferred + " m_iBytesSent=" + m_iBytesSent); 

     if (m_SendAsyncEventArgs.SocketError != SocketError.Success) 
     { 
      Log.Error("Socket Error '" + m_SendAsyncEventArgs.SocketError.ToString() + 
       "' in PSConnection ProcessSend. Connection ID: " + ConnectionId); 
      return false; 
     } 

     if (m_iBytesSent == m_iSendBufferLength) // this packet is finished sending 
     { 
      m_SendQueueMutex.WaitOne(); 
      ResetSendVars(); 
      m_SendQueueMutex.ReleaseMutex(); 
      CheckStartSend(); 
     } 
     else // still more of this clump to send 
     { 
      if (ConnectionSocket != null) 
      { 
       return StartSend(); 
      } 
      else 
      { 
       return false; 
      } 
     } 
     return true; 
    } 

, 도움이 될 정보의 흥미로운 비트 : 만 세 INT32 년대를 직렬화하는 경우는, 패킷이 전송됩니다 괜찮아요, ConnectionReset, 다른 Int32를 추가하면 오류가 발생합니다.

+0

나는 패킷 전송 코드를 포함하도록 게시물을 편집했습니다. 나는 대부분 내가 ConnectionReset의 소스를 추적하는 방법을 찾고있다. 디버깅이 안된다고 가정하고 시작하기 위해 코드를 게시하지 않았다. –

+0

오류를 표시 할 수 있습니까? 편집 할 때 나를 핑할 수 있습니다. –

+0

@YvetteColomb 감사에 대한 자세한 정보를 포함하도록 게시물을 업데이트했습니다. 감사합니다. –

답변

0

문제점을 파악했습니다. 우리 서버에서 보낸 패킷을받을 때 예외가 발생하여 클라이언트가 연결이 끊어졌습니다. 서버쪽에 초점을 맞추었지만 클라이언트에 문제가있었습니다.