Hello, I use byte[] to receive, unable to deserialize
The sending end:
string mgs = Console.ReadLine();
User uu = new User()
{
Id = 1,
Name = mgs
};
MemoryStream stream = new MemoryStream();
IFormatter formatter = new BinaryFormatter();
formatter.Serialize(stream, uu);
stream.Flush();
byte[] theBytes = stream.ToArray();
stream.Close();
Console.WriteLine(NetworkComms.SendReceiveObject<byte[], string>(“Message”, “127.0.0.1”, 6003, “hehe”, 1000, theBytes));
Console.ReadLine();
The receiving end:
NetworkComms.AppendGlobalIncomingPacketHandler<byte[]>(“Message”, (header, connection, message) =>
{
IFormatter formatter = new BinaryFormatter();
MemoryStream stream = new MemoryStream(message);
User t = formatter.Deserialize(stream) as User;
stream.Close();
connection.SendObject(“hehe”, t.Name);
});
Connection.StartListening(ConnectionType.TCP,new IPEndPoint(IPAddress.Parse(“127.0.0.1”),6003));
Console.ReadKey(true);