How to handle socket error connection reset

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • zoho
    New Member
    • Mar 2012
    • 11

    How to handle socket error connection reset

    We have socketserver that was developed using SocketAyncEvent Args based loosely on based loosely on the MS sample at http://msdn.microsoft.com/en-us/libr...eventargs.aspx

    Recently we had an issue with the socket server , it is not accepting new connections at all.But after restarting the service it worked.It is happenning frequently.

    When I looked into the logs , I see lot of connection reset error on connecting it self.

    Code is something like below
    Code:
      private void ProcessAccept(SocketAsyncEventArgs e)
      {
            try
            {
               if (e.SocketError == SocketError.Success)
               {
        
                  code to read message from client.
        
               }else
               {
                    if (e.SocketError != SocketError.OperationAborted)
                                log.WarnFormat("Unexpected SocketError in ProcessAccept: {0},{1}",IP, e.SocketError.ToString());
               }
         }
         catch (Exception ex)
         {
              log.ErrorFormat("Exception in ProcessAccept: {0}",ex.Message);
         }
         try
         {
                        // Accept the next connection request
                  StartAccept(e);
         }
         catch (Exception ex)
         {
               log.Fatal("Could not listen for new connection", ex);
         }

    I get connectionreset message in else statement.
    My question is Do I need to close the socket in else statement , that returns SocketErros ? like e.AcceptSocket. Close() ;?How should I hanlde the connectionreset errors in this case?
Working...