示例#1
0
        private void EndAcceptTcpClient(IAsyncResult state)
        {
            var listener = state.AsyncState as TcpListener;

            if (listener == null)
            {
                return;
            }
            bool needAccept = true;

            try
            {
                var client  = listener.EndAcceptTcpClient(state);
                var channel = new TcpChannel(client);
                Accepted?.Invoke(this, channel);
            }
            catch (SocketException)
            {
                needAccept = true;
            }
            catch (ObjectDisposedException)
            {
                needAccept = false;
                return;
            }
            finally
            {
                if (needAccept)
                {
                    listener.BeginAcceptTcpClient(EndAcceptTcpClient, listener);
                }
            }
        }
示例#2
0
 async Task Listen()
 {
     while (true)
     {
         var       listener = _listener;
         TcpClient client   = null;
         try
         {
             if (_listener == null)
             {
                 return;
             }
             client = await listener.AcceptTcpClientAsync();
         }
         catch (ObjectDisposedException)
         {
             return;
         }
         if (_listener == null)
         {
             return;
         }
         var channel = new TcpChannel(client);
         Accepted?.Invoke(this, channel);
     }
 }
示例#3
0
 internal void OnAccepted(WebSocketSession session)
 {
     Accepted?.Invoke(this, new WebSocketServerAcceptedArgs()
     {
         Session = session
     });
 }
示例#4
0
        /// <summary>
        /// 客户端连入事件函数
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AcceptedEventHandler(object sender, SocketAsyncEventArgs e)
        {
            Socket listenSocket             = (Socket)sender;
            SocketAsyncEventArgs acceptArgs = new SocketAsyncEventArgs();

            acceptArgs.Completed += AcceptedEventHandler;
            try
            {
                if (!listenSocket.AcceptAsync(acceptArgs))
                {
                    AcceptedEventHandler(listenSocket, acceptArgs);
                }
                LogPool.Logger.LogInformation((int)LogEvent.套接字, $"accepted { e.AcceptSocket.Handle} {(IPEndPoint)e.AcceptSocket.LocalEndPoint} {(IPEndPoint)e.AcceptSocket.RemoteEndPoint}");
            }
            catch (ObjectDisposedException)
            {
                return;
            }

            SocketChannel channel = new SocketChannel(
                e.AcceptSocket,
                SocketType.Accept,
                (IPEndPoint)e.AcceptSocket.LocalEndPoint,
                (IPEndPoint)e.AcceptSocket.RemoteEndPoint,
                _handler);

            channel.Received += Received;
            Accepted?.Invoke(this, new AcceptedEventArgs
            {
                Socket  = e.AcceptSocket,
                Channel = channel
            });
        }
示例#5
0
        /// <summary>
        /// Can be used to create filtering of new connections.
        /// </summary>
        /// <param name="socket">Accepted socket</param>
        /// <returns>true if connection can be accepted; otherwise false.</returns>
        protected bool OnAcceptingSocket(Socket socket)
        {
            ClientAcceptedEventArgs args = new ClientAcceptedEventArgs(socket);

            Accepted?.Invoke(this, args);
            return(!args.Revoked);
        }
示例#6
0
 internal void OnAccepted(WebSocketSession session, System.Action callBack)
 {
     Accepted?.Invoke(this, new WebSocketServerAcceptedArgs()
     {
         Session = session,
         Call    = callBack,
     });
 }
示例#7
0
 protected virtual void OnAccept()
 {
     Raise(() => {
         Handlers?.Accept(new HandleContext {
             Session = this
         });
         Accepted?.Invoke(this, EventArgs.Empty);
     });
 }
示例#8
0
        public async Task <ISocket> AcceptAsync()
        {
            var socket = await _socket.AcceptAsync();

            var wrapper = new SocketTesterWrapper(socket, "accepted");

            Accepted?.Invoke(wrapper);

            return(wrapper);
        }
示例#9
0
        protected virtual void AcceptComplete(object sender, IOTaskCompleteEventArgs <SocketAcceptTask> e)
        {
            if (e.Task.Exception == null)
            {
                Accepted?.Invoke(this, new AcceptEventArgs(new AresTcpSocket(Formatter, e.Task.AcceptSocket)));
            }

            if (Socket != null)
            {
                Socket.QueueAccept(e.Task);
            }
        }
示例#10
0
        public TestChannelPair ImmitateAccept(TestChannel incomeChannel)
        {
            if (!IsListening)
            {
                throw  new  InvalidOperationException();
            }
            var thisChannel = new TestChannel();
            var pair        = TntTestHelper.CreateChannelPair(thisChannel, incomeChannel);

            pair.ConnectAndStartReceiving();
            Accepted?.Invoke(this, thisChannel);
            return(pair);
        }
示例#11
0
        private async Task ListenContinuouslyAsync()
        {
            while (Listening)
            {
                var client = await TcpListener.AcceptTcpClientAsync().ConfigureAwait(false);

                Task.Run(() =>
                {
                    var endPoint  = (IPEndPoint)client.Client.RemoteEndPoint;
                    var eventArgs = new Connection(endPoint.Address, endPoint.Port, ConnectionOptions, new TcpClientAdapter(client));
                    Accepted?.Invoke(this, eventArgs);
                }).Forget();
            }
        }
示例#12
0
        public override void HandleInput(GameTime gameTime, InputState input)
        {
            PlayerIndex playerIndex;

            if (menuSelect.Occurred(input, ControllingPlayer, out playerIndex))
            {
                Accepted?.Invoke(this, new PlayerIndexEventArgs(playerIndex));
                ExitScreen();
            }
            else if (menuCancel.Occurred(input, ControllingPlayer, out playerIndex))
            {
                Cancelled?.Invoke(this, new PlayerIndexEventArgs(playerIndex));
                ExitScreen();
            }
        }
示例#13
0
        private void OKB_Click(object sender, EventArgs e)
        {
            if (checkBox2.Checked)
            {
                textBox1.Text = textBox1.Text.Replace("-", "_");
            }
            Accepted?.Invoke(this, new EventArgs());

            if (SameIDAvailable)
            {
                return;
            }
            else
            {
                Close();
            }
        }
示例#14
0
        /// <summary>
        /// The callback for BeginAccept
        /// </summary>
        /// <param name="ar"></param>
        private void acceptCallback(IAsyncResult ar)
        {
            try
            {
                //Get the connected socket.
                var accepted = this.listener.EndAccept(ar);

                //Starts the loop again.
                this.listener.BeginAccept(acceptCallback, null);

                //Call the Accepted event.
                Accepted?.Invoke(this, new AcceptedTcpSocketEventArgs(accepted));
            }
            catch (Exception ex)
            {
                Debug.Print(ex.StackTrace);
            }
        }
示例#15
0
 public override void HandleInput(GameTime gameTime, InputState input)
 {
     // We pass in our ControllingPlayer, which may either be null (to
     // accept input from any player) or a specific index. If we pass a null
     // controlling player, the InputState helper returns to us which player
     // actually provided the input. We pass that through to our Accepted and
     // Cancelled events, so they can tell which player triggered them.
     if (_menuSelect.Occurred(input, ControllingPlayer, out var playerIndex))
     {
         Accepted?.Invoke(this, new PlayerIndexEventArgs(playerIndex));
         ExitScreen();
     }
     else if (_menuCancel.Occurred(input, ControllingPlayer, out playerIndex))
     {
         Cancelled?.Invoke(this, new PlayerIndexEventArgs(playerIndex));
         ExitScreen();
     }
 }
示例#16
0
        private void Apply_OnPointerPressed(object?sender, PointerPressedEventArgs e)
        {
            if (_currentAction != null)
            {
                Accepted?.Invoke(this, _currentAction);

                if (CurrentSide == Devices.L)
                {
                    SettingsProvider.Instance.CustomActionLeft.Action    = _currentAction.Action;
                    SettingsProvider.Instance.CustomActionLeft.Parameter = _currentAction.Parameter;
                }
                else
                {
                    SettingsProvider.Instance.CustomActionRight.Action    = _currentAction.Action;
                    SettingsProvider.Instance.CustomActionRight.Parameter = _currentAction.Parameter;
                }
            }

            MainWindow.Instance.Pager.SwitchPage(Pages.Touch);
        }
示例#17
0
        // Handle Input

        /// Responds to user input, accepting or cancelling the message box.
        public override void HandleInput()
        {
            if (InputManager.IsActionTriggered(InputManager.Action.Ok))
            {
                // Raise the accepted event, then exit the message box.
                Accepted?.Invoke(this, EventArgs.Empty);

                AudioManager.PlayCue("closeWindow");

                ExitScreen();
            }
            else if (InputManager.IsActionTriggered(InputManager.Action.Back))
            {
                // Raise the cancelled event, then exit the message box.
                Cancelled?.Invoke(this, EventArgs.Empty);

                AudioManager.PlayCue("closeWindow");

                ExitScreen();
            }
        }
示例#18
0
        private void AcceptCompleted(object sender, SocketAsyncEventArgs args)
        {
            if (args.SocketError == SocketError.Success)
            {
                SocketAsyncEventArgs rArgs = new SocketAsyncEventArgs();
                rArgs.Completed   += ReceiveCompleted;
                rArgs.AcceptSocket = args.AcceptSocket;
                rArgs.SetBuffer(new byte[8912], 0, 8912);
                rArgs.UserToken = new MemoryStream();

                _clients.Add(args.AcceptSocket);
                if (Accepted != null)
                {
                    Accepted.Invoke(this, args.AcceptSocket);
                }

                try
                {
                    if (!rArgs.AcceptSocket.ReceiveAsync(rArgs))
                    {
                        ReceiveCompleted(this, rArgs);
                    }

                    args.AcceptSocket = null;
                    if (!_server.AcceptAsync(args))
                    {
                        AcceptCompleted(this, args);
                    }
                }
                catch (NotSupportedException nse) { throw nse; }
                catch (ObjectDisposedException oe) { throw oe; }
                catch (SocketException se) { throw se; }
                catch (Exception e) { throw e; }
            }
            else
            {
                _clients.Remove(args.AcceptSocket);
                args.AcceptSocket.Close();
            }
        }
示例#19
0
        private void Accept(IAsyncResult AR)
        {
            Socket clientSocket;

            try
            {
                clientSocket = socket.EndAccept(AR);
                clients.Add(clientSocket);

                Log?.Invoke(((IPEndPoint)clientSocket.RemoteEndPoint).Address + " connected");

                Accepted?.Invoke(clientSocket);

                socket.BeginAccept(Accept, null);

                clientSocket.BeginReceive(buffer, 0, BUFFER_SIZE, SocketFlags.None, Receive, clientSocket);
            }
            catch (ObjectDisposedException e)
            {
                return;
            }
        }
示例#20
0
        private static void OnReceiveProc(IAsyncResult ar)
        {
            var wrapObject = ar.AsyncState as WrapObject;

            Socket     handler        = wrapObject.Handler;
            IPEndPoint remoteEndPoint = (IPEndPoint)handler.RemoteEndPoint;

            byte[] buf = wrapObject.Buffer;

            if (handler == null)
            {
                throw new Exception("Not Exists Handler object");
            }

            if (handler != null)
            {
                try
                {
                    int count = handler.EndReceive(ar);
                    if (count > 0)
                    {
                        string msg = Encoding.UTF8.GetString(buf, 0, count);

                        AcceptEventArgs e = new AcceptEventArgs(remoteEndPoint, msg);
                        Accepted?.Invoke(typeof(AcceptServer), e);
                    }

                    wrapObject = new WrapObject
                    {
                        Handler = handler,
                        Buffer  = new byte[256]
                    };

                    handler.BeginReceive(buf, 0, buf.Length, SocketFlags.None, asyncReceive, wrapObject);
                }
                catch (SocketException e) { }
            }
        }
示例#21
0
        /// <summary>
        /// Responds to user input, accepting or cancelling the message box.
        /// </summary>
        public override void HandleInput(GameTime gameTime, InputState input)
        {
            PlayerIndex playerIndex = PlayerIndex.One;

            // We pass in our ControllingPlayer, which may either be null (to
            // accept input from any player) or a specific index. If we pass a null
            // controlling player, the InputState helper returns to us which player
            // actually provided the input. We pass that through to our Accepted and
            // Cancelled events, so they can tell which player triggered them.
            if (menuSelect?.Evaluate(input, ControllingPlayer, out playerIndex) ?? false)
            {
                // Raise the accepted event, then exit the message box.
                Accepted?.Invoke(this, new PlayerIndexEventArgs(playerIndex));

                ExitScreen();
            }
            else if (menuCancel?.Evaluate(input, ControllingPlayer, out playerIndex) ?? false)
            {
                // Raise the cancelled event, then exit the message box.
                Cancelled?.Invoke(this, new PlayerIndexEventArgs(playerIndex));

                ExitScreen();
            }
        }
示例#22
0
文件: MitmListner.cs 项目: nikes/Link
        protected virtual void ProcessConnections(Connection client, Connection server)
        {
            try
            {
                var pair = MakePair();
                ConfigurePair(pair);

                pair.Client.SetupConnection(client, false);
                pair.Server.SetupConnection(server, false);

                Accepting?.Invoke(this, pair);

                pair.Initialize();
                pair.Client.Start();
                pair.Server.Start();

                Accepted?.Invoke(this, pair);
            }
            catch
            {
                ActiveFactory.Free(client);
                PassiveFactory.Free(server);
            }
        }
示例#23
0
 protected virtual void OnAccepted()
 {
     Accepted?.Invoke(this, EventArgs.Empty);
 }
示例#24
0
 protected virtual void OnAccepted(AcceptedEventArgs e)
 {
     Accepted?.Invoke(this, e);
 }
示例#25
0
 protected void NotifyAccepted(Socket socket) => Accepted?.Invoke(socket);
 public void Accept()
 {
     IsAccepted = true;
     Accepted?.Invoke(this, EventArgs.Empty);
     Dismiss();
 }
示例#27
0
 private void Listner_MitmPairAccepted(object sender, T pair)
 {
     sessions.Add(pair);
     Accepted?.Invoke(this, pair);
 }
示例#28
0
 private void OnAccepted(object sender, EventArgs e)
 {
     Accepted?.Invoke(this, null);
 }
示例#29
0
 private void AcceptClick(object sender, RoutedEventArgs e)
 {
     Accepted?.Invoke(this);
 }
示例#30
0
 private void btnAccept_Click(object sender, EventArgs e)
 {
     Accepted?.Invoke(txtInput.Text);
     Close();
 }