Ejemplo n.º 1
0
 internal Peer(IConnection connection)
 {
     _connection = connection;
     _sendSpeedWatcher = new SpeedWatcher();
     _receiveSpeedWatcher = new SpeedWatcher();
     _receiveBandwidthController = new UnlimitedBandwidthController();
     _sendBandwidthController = new UnlimitedBandwidthController();
     _statistics = new PeerStat();
     _uri = new Uri("tcp://" + EndPoint.Address + ':' + EndPoint.Port);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CommunicationManager"/> class.
        /// </summary>
        /// <example>
        ///    var portNumber = 9876;
        ///    var listener = new Listener(portNumber);
        ///    var comunicationManager = new CommunicationManager(_listener);
        ///    comunicationManager.PeerConnected += ChatOnMemberConnected;
        ///    comunicationManager.ConnectionClosed += ChatOnMemberDisconnected;
        ///    comunicationManager.ConnectionFailed += ChatOnMemberConnectionFailure;
        ///    comunicationManager.PeerDataReceived += OnPeerDataReceived;
        ///
        ///    listener.Start();
        /// </example>
        /// <param name="listener">The incomming connections <see cref="Listener"/>.</param>
        public CommunicationManager(TcpListener listener)
        {
            _listener = listener;
            _worker = new ClientWorker();
            _ioActor = new ConnectionIoActor(_worker, new BufferAllocator(new byte[1 << 16]));
            _peers = new ConcurrentDictionary<IPEndPoint, Peer>();

            _globalReceiveSpeedWatcher = new SpeedWatcher();
            _globalSendSpeedWatcher = new SpeedWatcher();

            _worker.QueueForever(CalculateSpeed, 500.Milliseconds());
            _worker.Start();

            _listener.ConnectionRequested += NewPeerConnected;
        }