Problem with Socket and Serialization C#

前端 未结 6 1147
陌清茗
陌清茗 2021-01-27 13:23

I implemented a Client and Server model that uses Socket with thread

When I want to pass only a string from Client to the Server, it works. But I want to pass an object

6条回答
  •  自闭症患者
    2021-01-27 13:30

    Instead of passing bytesRead to the MemoryStream which is actually the length of the byte stream, you should pass 'message', as it is the actual stream of bytes. Like,

    MemoryStream memoryStream = new MemoryStream(message);
    

    As you are passing an integer variable, the compiler is throwing exception that the stream is empty.

    As for WCF, it is remarkable framework, but for applications that require low latency and high performance, WCF is a horrible answer because of its overheads, it is built upon sockets. So if you use sockets, that will be the lowest level implementation and thus, the fastest. That depends on your application which paradigm you should choose...

提交回复
热议问题