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
Expand|Select|Wrap|Line Numbers
- 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?