/// <summary> /// Enqueue the package in the message queue to send this to the server. /// </summary> /// <param name="package">Package to send (must inherit <see cref="BasePackage"/>).</param> public void EnqueueDataForWrite(BasePackage package) { if (!TcpClient.Connected) { throw new InvalidOperationException("You're not connected!"); } var packageBytes = BasePackage.Serialize(package); var length = packageBytes.Length; var lengthBytes = BitConverter.GetBytes(length); PendingDataToWrite.Enqueue(lengthBytes); PendingDataToWrite.Enqueue(packageBytes); lock (PendingDataToWrite) { if (SendingData) { return; } SendingData = true; } WriteData(); }
/// <summary> /// Enqueue the packet in the message queue to send this to the client. /// </summary> /// <param name="package">Package to send (must inherit <see cref="BasePackage"/>).</param> public void EnqueueDataForWrite(BasePackage package) { var packageBytes = BasePackage.Serialize(package); var length = packageBytes.Length; var lengthBytes = BitConverter.GetBytes(length); _pendingDataToWrite.Enqueue(lengthBytes); _pendingDataToWrite.Enqueue(packageBytes); lock (_pendingDataToWrite) { if (_sendingData) { return; } _sendingData = true; } WriteData(); }