private OTcpServerHeader SendHeader(ref TcpClient client, int messageSize, string command, string expectType, Guid token) { var header = new OTcpServerHeader(Commands.GetHashOfCommand(command), messageSize, expectType, token); var headerBytes = ObjectBinarySerialization.ObjectToByteArray(header); client.GetStream().Write(headerBytes, 0, headerBytes.Length); return(header); }
private void SendBinary <T>(string command, T messageData) { var data = ObjectBinarySerialization.ObjectToByteArray(messageData); var header = new OTcpServerHeader(Commands.GetHashOfCommand(command), data.LongLength, (messageData).GetType().FullName); int headerSize = OTcpServerHeader.HeaderSize; _currentStream.Write(ObjectBinarySerialization.ObjectToByteArray(header), 0, headerSize); _currentStream.Write(data, 0, data.Length); // Write the bytes }
private void SendBinary <T>(ref TcpClient client, T message, string command, Guid token) { try { var messageBytes = ObjectBinarySerialization.ObjectToByteArray(message); var messageSize = messageBytes.Length; SendHeader(ref client, messageSize, command, message.GetType().FullName, token); // token handle client.GetStream().Write(messageBytes, 0, messageSize); } catch (Exception e) { Console.WriteLine(e.Message); throw e; } }
private void SendJSON <T>(string command, T messageData) { try { var data = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(messageData)); var header = new OTcpServerHeader(Commands.GetHashOfCommand(command), data.LongLength, (messageData).GetType().FullName); int headerSize = OTcpServerHeader.HeaderSize; _currentStream.Write(ObjectBinarySerialization.ObjectToByteArray(header), 0, headerSize); _currentStream.Write(data, 0, data.Length); // Write the bytes } catch (Exception e) { Console.WriteLine(e.Message); throw e; } }