private void AcceptCallback(IAsyncResult ar)
 {
     ThreadNotifier.Set();
     Listener      = (Socket)ar.AsyncState;
     CurrentClient = new ClientSocketAsync(Listener.EndAccept(ar));
     OnClientAccepted?.Invoke(this, CurrentClient);
 }
示例#2
0
        public async Task acceptClient()
        {
            OnListeningForClient.Invoke(this, new ServerEventArgs("Server Accepting Clients."));

            client = await server.AcceptTcpClientAsync();

            OnClientAccepted.Invoke(this, new ServerEventArgs("Server Accepted Client."));
        }
示例#3
0
 /// <summary>
 /// Process a new connected client.
 /// </summary>
 /// <param name="socketAsyncEvent">Socket async event arguments.</param>
 private void ProcessAccept(SocketAsyncEventArgs socketAsyncEvent)
 {
     if (socketAsyncEvent.SocketError == SocketError.Success)
     {
         OnClientAccepted?.Invoke(this, socketAsyncEvent);
         StartAccept();
     }
 }
示例#4
0
 private void EndAccept(IAsyncResult iar)
 {
     try
     {
         var socket = m_sock.EndAccept(iar);
         OnClientAccepted?.Invoke(socket);
     }
     catch (ObjectDisposedException) { }
     catch (SocketException) { }
     finally
     {
         BeginAccept();
     }
 }
示例#5
0
        /// <summary>
        /// Process a new connected client.
        /// </summary>
        /// <param name="socketAsyncEvent">Socket async event arguments.</param>
        private void ProcessAccept(SocketAsyncEventArgs socketAsyncEvent)
        {
            if (socketAsyncEvent.SocketError == SocketError.Success)
            {
                try
                {
                    OnClientAccepted?.Invoke(this, socketAsyncEvent);
                }
                catch (Exception exception)
                {
                    OnError?.Invoke(this, exception);
                }

                StartAccept();
            }
        }
示例#6
0
        private void EndAccept(IAsyncResult iar)
        {
            try
            {
                Event.Set();

                var socket = Socket.EndAccept(iar);
                OnClientAccepted?.Invoke(socket);
            }
            catch (ObjectDisposedException)
            {
                //Nothing
            }
            catch (Exception ex)
            {
                OnException?.Invoke(ex);
            }
        }