Beispiel #1
0
 private void Client_OnExceptionHappenedEvent(object arg1, ExceptionHappenedArgs arg2)
 {
     if (OnExceptionHappenedEvent != null)
     {
         OnExceptionHappenedEvent(this, arg2);
     }
 }
 protected void Callback_SocketExceptionHappened(object sender, ExceptionHappenedArgs args)
 {
     if (OnExceptionHappenedEvent != null)
     {
         OnExceptionHappenedEvent(sender, args);
     }
 }
Beispiel #3
0
 /// <summary>
 /// 一个连接接收完成
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void OnAcceptCompleted(object sender, SocketAsyncEventArgs e)
 {
     if (m_state != (int)EnumNetworkStatus.Established)
     {
         return;
     }
     if (e.SocketError == SocketError.Success)
     {
         //和客户端关联的socket
         Socket socket = e.AcceptSocket;
         try
         {
             if (socket.Connected)
             {
                 var client = new SocketNetClient <TBuilder, TPackage>(socket,
                                                                       EnumNetworkType.TCP,
                                                                       NetworkGlobal.TCP_RECEIVE_BUFFER_SIZE,
                                                                       NetworkGlobal.TCP_SOCKET_RECEIVE_SIZE,
                                                                       NetworkGlobal.TCP_SOCKET_SEND_SIZE);
                 client.OnSocketStatusChangedEvent += Client_OnClientSocketStatusChangedEvent;
                 client.OnDataReceivedEvent        += Client_OnDataReceivedEvent;
                 client.OnExceptionHappenedEvent   += Client_OnExceptionHappenedEvent;
                 //更新上线
                 m_clients.AddOrUpdate((IPEndPoint)socket.RemoteEndPoint, client, (v, k) => { return(client); });
                 //启动收收数
                 client.StartReceive();
                 //上线通知
                 if (OnClientSocketStatusChangedEvent != null)
                 {
                     var args = new SocketStatusChangedArgs <TPackage>(EnumNetworkStatus.Established, client);
                     OnClientSocketStatusChangedEvent(this, args);
                 }
             }
         }
         catch (SocketException ex)
         {
             if (OnExceptionHappenedEvent != null)
             {
                 var args = new ExceptionHappenedArgs((IPEndPoint)socket.RemoteEndPoint, "处理客户端连接上线失败", ex);
                 OnExceptionHappenedEvent(this, args);
             }
         }
     }
     //投递下一个接受请求
     StartAcceptConnection(e);
 }