public override void Dispose() { CancellationToken?.Cancel(); Stream?.Dispose(); #if DEBUG PacketsReceived?.Clear(); PacketsSended?.Clear(); #endif CancellationToken?.Dispose(); }
public void SendPacket(ProtobufPacket packet) { if (!Connected) { throw new ProtocolException("Connection error: Not connected to server."); } Stream.SendPacket(packet); #if DEBUG PacketsSended.Add(packet); #endif }
public async Task SendPacketAsync(IPacket packet) { if (!Connected) { throw new ProtocolException("Connection error: Not connected to server."); } await _stream.SendPacketAsync(packet); if (SavePackets) { PacketsSended.Add(packet); } }
public void SendPacket(ref IPacket packet) { if (!Connected) { throw new ProtocolException("Connection error: Not connected to server."); } _stream.SendPacket(ref packet); if (SavePackets) { PacketsSended.Add(packet); } }
public void Dispose() { if (_stream != null) { _stream.Dispose(); } if (PacketsReceived != null) { PacketsReceived.Clear(); } if (PacketsSended != null) { PacketsSended.Clear(); } }
public IAsyncResult BeginSendPacket(IPacket packet, AsyncCallback asyncCallback, object state) { if (!Connected) { throw new Exception("Connection error"); } if (DebugPackets) { PacketsSended.Add(packet); } IAsyncResult result = BeginSend(packet, asyncCallback, state); EndSend(result); return(result); }