void PostMessageInternal (BinaryMessage message) { if ((status != ConnectionStatus.Connected || disposed) && !message.BypassConnection) { ProcessResponse (message.CreateErrorResponse ("Connection is closed")); return; } try { if (DebugMode) message.SentTime = DateTime.Now; // Now send the message. This one will need a response if (DebugMode) LogMessage (MessageType.Request, message); connectionStream.WriteByte ((byte)RequestType.QueueEnd); message.Write (connectionStream); connectionStream.Flush (); } catch (Exception ex){ if (connection == null || (!connection.Connected && status == ConnectionStatus.Connected)) { AbortConnection ("Disconnected from remote process due to a communication error", isAsync: true); } else ProcessResponse (message.CreateErrorResponse (ex.ToString ())); } }
public void WriteMessage(byte type, BinaryMessage msg) { msg.ReadCustomData(); lock (listeners) { if (DebugMode) { Console.WriteLine("[SERVER] XS << RP " + type + " [" + msg.ProcessingTime + "ms] " + msg); } outStream.WriteByte(type); try { msg.Write(outStream); } catch (Exception ex) { msg.CreateErrorResponse(ex.ToString(), true).Write(outStream); } } }