/// <summary> /// Write the JSON message to the output stream. /// </summary> /// <param name="message"> /// The message to write. /// </param> private void WriteJsonMessage(string message) { // Build the header message. var header = string.Format("Content-Length: {0}{1}{2}{1}{2}", message.Length, (char)0x0D, (char)0x0A); var headerData = Encoding.UTF8.GetBytes(header); SourceStream.Write(headerData, 0, headerData.Length); // Write the body data. var bodyData = Encoding.UTF8.GetBytes(message); SourceStream.Write(bodyData, 0, bodyData.Length); SourceStream.Flush(); // debug the new message. if (DebugStream != null) { lock (DebugStream) { DebugStream.WriteLine("*****************************************"); DebugStream.WriteLine(" Direction: {0}", Direction); DebugStream.WriteLine(" Timestamp: {0}", DateTime.Now); DebugStream.WriteLine("*****************************************"); DebugStream.WriteLine(message); DebugStream.WriteLine("*****************************************"); DebugStream.Flush(); } } }
/// <summary> /// Flushes the underlying stream /// </summary> public override void Flush() { SourceStream.Flush(); }