public static ReadFromStreamAsync ( |
||
stream | ||
Результат | Task |
private async Task ProcessPacketStream() { try { while (IsConnected && (OutgoingPackets.Count != 0 || TcpClient.Available != 0)) { while (IsConnected && TcpClient.Available != 0) { if (ReceivedPacket != null) { ReceivedPacket(this, new PacketEventArgs() { Packet = await Packet.ReadFromStreamAsync(TcpClientStream) }); } IncomingPacketReceieved = true; } if (IsConnected && CanSendPacket && OutgoingPackets.Count != 0) { await OutgoingPackets.Dequeue().WriteToStreamAsync(TcpClientStream); OutgoingPacketCooldown.Restart(); IncomingPacketReceieved = false; } //// We've successfully sent or recieved data so the keepalive can be pushed back. //Keepalive.Reset(); } } catch { // Lost connection with the server // No handling is necessary here as the TCPClient will set Connected to false. if (ServerConnectionDropped != null) { ServerConnectionDropped(this, new ServerConnectionEventArgs() { Message = "Connection to the server has been lost.", Status = ServerConnectionStatus.Disconnected, Timestamp = DateTime.Now }); } } }