public void Write(CMD_Base cmd, bool debug = true) { if (debug) // use intermediate StringStream to Debug Dump before sending to network { StringWriter strWR = new StringWriter(); var dummy_LJ_Writer = new LightJson.Serialization.JsonWriter(strWR); WriteInternal(cmd, dummy_LJ_Writer); streamWriter.Write(strWR.ToString().NLSend("WROTE| ")); } else { WriteInternal(cmd, LJ_Writer); } streamWriter.Flush(); // TODO guesswork , i want immediate genereation of TCP packet at this point. MSDN is pretty obtuse in this regard }
public LightJsonTCPAdapter(TcpClient connectedClient) { if (!connectedClient.Connected) { throw new Exception(); } if (!connectedClient.Client.Blocking) { throw new Exception(); } TCPcl = connectedClient; netwStreamAdapter = new BlockingPeekReader(TCPcl.GetStream()); streamWriter = new StreamWriter(TCPcl.GetStream()); LJ_Reader = new LightJson.Serialization.JsonReader(netwStreamAdapter); LJ_Writer = new LightJson.Serialization.JsonWriter(streamWriter); }
public void WriteInternal(CMD_Base cmd_base, LightJson.Serialization.JsonWriter LJ_Writer) // with explicit stream adapter for convenient unit tesing { LJ_Writer.Write(cmd_base.LJ_Value()); }