Esempio n. 1
0
        /// <summary>
        /// Клиент установил соединение с сервером
        /// </summary>
        /// <param name="sender">Источник события</param>
        /// <param name="e">Параметры события</param>
        void OnConnect(object sender, ServerEventArgs e)
        {
            TcpAsyClient client = new TcpAsyClient();

            client.Socket = e.Socket;
            client.Socket.SendTimeout = 1000;

            client.Share = shareClientMutex;
            client.OnPacket += new TcpAsyClient.PacketEventHandler(client_OnPacket);

            bool blocked = false;
            try
            {
                if (mutex.WaitOne(100, false))
                {
                    blocked = true;
                    clients.Add(client);
                }
            }
            finally
            {
                if (blocked) mutex.ReleaseMutex();
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Разорвал с серверос соединение клиент
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void server_OnDisconnect(object sender, ServerEventArgs e)
 {
     bool blocked = false;
     try
     {
         if (mutex.WaitOne(100, false))
         {
             blocked = true;
             foreach (TcpAsyClient client in clients)
             {
                 if (client.Socket.Handle == e.Socket.Handle)
                 {
                     clients.Remove(client);
                     break;
                 }
             }
         }
     }
     finally
     {
         if (blocked) mutex.ReleaseMutex();
     }
 }