internal void Read(int size) { _Offset = 0; _Buffer = new byte[size]; try { _Peer.Receive(_Buffer, _Offset, _Buffer.Length - _Offset, _Readed); } catch (SystemException e) { if (ErrorEvent != null) { ErrorEvent(); } } }
public void StartFor(IPeer peer, CancellationToken cancellationToken) { // Initiate handshake peer.Send(new VersionMessage(_serverContext.Version)); Task.Factory.StartNew(async() => { while (peer.IsConnected) { var message = await peer.Receive(); if (message == null) { await _asyncDelayer.Delay(DefaultMessagePollingInterval, cancellationToken); continue; } // TODO: Peer that sending wrong messages has to be disconnected. if (peer.IsReady == message.IsHandshakeMessage()) { continue; } await _messageHandler.Handle(message, peer); } }, cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Default); }
private void _Read() { try { _Peer.Receive(_ReadedByte, 0, 1, _Readed); } catch (SystemException e) { if (_ErrorEvent != null) { _ErrorEvent(); } } }
private void ListenForIncomingMessages(IPeer peer) { Task.Factory.StartNew(async() => { while (peer.IsConnected) { var message = await peer.Receive(); if (!peer.IsReady && !IsHandshakeMessage(message)) { continue; } await _messageHandler.Handle(message, peer); await Task.Delay(1000, _stopTokenSource.Token); } }, _stopTokenSource.Token, TaskCreationOptions.LongRunning, TaskScheduler.Default); }
private void ListenForMessages(IPeer peer, CancellationToken cancellationToken) { Task.Factory.StartNew(async() => { while (peer.IsConnected) { var message = await peer.Receive(); if (!peer.IsReady && message.IsNotHandshakeMessage()) { continue; } await this._messageHandler.Handle(message, peer); await Task.Delay(1000, cancellationToken); } }, cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Default); }
void IStage.Enter() { _Peer.Receive(_Buffer, 0, _Buffer.Length, _Readed); }