/// <summary> /// Asynchronous peer connection callback. When a connection /// is completed try to add it to the swarm via the connector /// passed as a parameter. /// </summary> /// <param name="ar"></param> private void ConnectionAsyncHandler(IAsyncResult ar) { AgentConnector connector = (AgentConnector)ar.AsyncState; try { connector.socket.EndConnect(ar); connector.callBack(connector); } catch (Exception ex) { connector.socket?.Close(); Log.Logger.Error("Error (Ignored): " + ex.Message); } }
internal static int listenPort = Host.DefaultPort; // Listener port /// <summary> /// Asynchronous remote peer connection callback. When a remote connection /// arrives try to add it to the swarm via the connector passed then prime /// the accept callback for the next peers connection attempt. /// </summary> /// <param name="ar"></param> private void AcceptAsyncHandler(IAsyncResult ar) { AgentConnector connector = (AgentConnector)ar.AsyncState; try { connector.socket = _listenerSocket.EndAccept(ar); connector.callBack(connector.Copy()); _listenerSocket.BeginAccept(new AsyncCallback(AcceptAsyncHandler), connector); } catch (Exception ex) { connector.socket?.Close(); Log.Logger.Error(ex); Log.Logger.Info("Port connection listener terminated."); } }