コード例 #1
0
 /// <summary>
 /// 主动断开会话
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="closeSessionArgs"></param>
 protected virtual void OnCloseSession(object sender, CloseSessionArgs closeSessionArgs)
 {
     try
     {
         if (closeSessionArgs.Session.SocketAsyncEventArgs.AcceptSocket != null)
         {
             closeSessionArgs.Session.SocketAsyncEventArgs.AcceptSocket.BeginDisconnect(false, (result) =>
             {
                 CloseSessionArgs args = result.AsyncState as CloseSessionArgs;
                 if (args.Session.SocketAsyncEventArgs.AcceptSocket != null)
                 {
                     try
                     {
                         args.Session.SocketAsyncEventArgs.AcceptSocket.Shutdown(SocketShutdown.Both);
                     }
                     catch (Exception ex)
                     {
                         _logger.Error(ex);
                     }
                 }
             }, closeSessionArgs);
         }
     }
     catch (Exception ex)
     {
         _logger.Error(ex);
     }
 }
コード例 #2
0
 public virtual void OnClosed(CloseSessionArgs closeSessionArgs) 
 {
     Closed(this,closeSessionArgs);
 }