Beispiel #1
0
        /// <summary>
        /// Обработчик события при попытке принять входящее соединение
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="socketArgs"></param>
        private void AcceptSocketOnCompleted(object sender, SocketAsyncEventArgs socketArgs)
        {
            if (socketArgs.SocketError != SocketError.Success)
            {
                return;
            }

            lock (HandlerSockets)
            {
                _currentClientId = Guid.NewGuid();
                var hSocket = new HandlerSocket(socketArgs.AcceptSocket, _currentClientId);
                HandlerSockets.Add(_currentClientId, hSocket);
                OnClientConnect?.Invoke(_currentClientId);
            }

            try
            {
                AwaitRecieveData(_currentClientId);
                var argsAcceptSocket = new SocketAsyncEventArgs();
                argsAcceptSocket.Completed += AcceptSocketOnCompleted;
                _listenerSocket.AcceptAsync(argsAcceptSocket);
            }
            catch (SocketException socketException)
            {
                OnClientDisconnect?.Invoke(_currentClientId);
                Debug.WriteLine(socketException.Message);
            }
        }
Beispiel #2
0
 public Packet(HandlerSocket socket)
 {
     HSocket = socket;
 }