Example #1
0
 private void AcceptCallback(object sender, SocketAsyncEventArgs args)
 {
     if (args.SocketError == SocketError.Success && args.AcceptSocket != null)
     {
         var client = new FlexiSocket(args.AcceptSocket, _protocol);
         lock (_clients)
             _clients.Add(client);
         if (ReceivedFromClient != null)
         {
             client.Received += delegate(bool success, Exception exception, SocketError error, byte[] message)
             {
                 if (success)
                 {
                     ReceivedFromClient(client, message);
                 }
             }
         }
         ;
         if (ReceivedFromClientAsString != null)
         {
             client.ReceivedAsString +=
                 delegate(bool success, Exception exception, SocketError error, string message)
             {
                 if (success)
                 {
                     ReceivedFromClientAsString(client, message);
                 }
             }
         }
         ;
         if (ClientDisconnected != null)
         {
             client.Closed += delegate
             {
                 lock (_clients)
                     _clients.Remove(client);
                 ClientDisconnected(client);
             };
         }
         if (SentToClient != null)
         {
             client.Sent +=
                 delegate(bool success, Exception exception, SocketError error)
             {
                 SentToClient(success, client);
             }
         }
         ;
         if (ClientConnected != null)
         {
             ClientConnected(client);
         }
         client.StartReceive(null, new StateObject(client._socket, _protocol));
         StartAccept(args);
     }
 }