public async Task SendPacket(ServerPacket packet) { byte[] writeBuffer = packet.GetBytes(); if (writeBuffer.Length > bufferSize) { throw new Exception("Write buffer was too large to send!"); } try { await stream.WriteAsync(writeBuffer, 0, writeBuffer.Length); Debug.Log($"Sent packet to client {ID}. Bytes written: {writeBuffer.Length}, pakcet code: {packet.GetPacketCode()}"); } catch { Debug.Log("Failed to send data to client!"); Disconnect(); } }
internal void SendPacket(TcpClient client, ServerPacket packet) { }
/// <summary> /// Sends packet to client with specified ID /// </summary> /// <param name="packet"></param> /// <param name="ID"></param> public async void SendPacketToClient(ServerPacket packet, int ID) { await clients[ID].SendPacket(packet); }