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); } } }
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); } }
internal void OnAccepted(WebSocketSession session) { Accepted?.Invoke(this, new WebSocketServerAcceptedArgs() { Session = session }); }
/// <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 }); }
/// <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); }
internal void OnAccepted(WebSocketSession session, System.Action callBack) { Accepted?.Invoke(this, new WebSocketServerAcceptedArgs() { Session = session, Call = callBack, }); }
protected virtual void OnAccept() { Raise(() => { Handlers?.Accept(new HandleContext { Session = this }); Accepted?.Invoke(this, EventArgs.Empty); }); }
public async Task <ISocket> AcceptAsync() { var socket = await _socket.AcceptAsync(); var wrapper = new SocketTesterWrapper(socket, "accepted"); Accepted?.Invoke(wrapper); return(wrapper); }
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); } }
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); }
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(); } }
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(); } }
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(); } }
/// <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); } }
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(); } }
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); }
// 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(); } }
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(); } }
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; } }
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) { } } }
/// <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(); } }
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); } }
protected virtual void OnAccepted() { Accepted?.Invoke(this, EventArgs.Empty); }
protected virtual void OnAccepted(AcceptedEventArgs e) { Accepted?.Invoke(this, e); }
protected void NotifyAccepted(Socket socket) => Accepted?.Invoke(socket);
public void Accept() { IsAccepted = true; Accepted?.Invoke(this, EventArgs.Empty); Dismiss(); }
private void Listner_MitmPairAccepted(object sender, T pair) { sessions.Add(pair); Accepted?.Invoke(this, pair); }
private void OnAccepted(object sender, EventArgs e) { Accepted?.Invoke(this, null); }
private void AcceptClick(object sender, RoutedEventArgs e) { Accepted?.Invoke(this); }
private void btnAccept_Click(object sender, EventArgs e) { Accepted?.Invoke(txtInput.Text); Close(); }