C# send structure objects through socket

前端 未结 6 1774
自闭症患者
自闭症患者 2020-12-09 22:18

i have done a bit of reading in client/server programming in c#. i am familiar enough with this process to ask the following question:

how do i transmit structure ob

6条回答
  •  被撕碎了的回忆
    2020-12-09 23:15

    You're on the right track with using object serialization.

    One thing I would think about that I haven’t seen mentioned yet is that binary serializers will generally create a less bytes to send over the socket, however if you use a XML or JSON serializer and then compress the results using a CompressionStream (GZipStream?) before you send it over your network stream you may get even smalelr sizes based on the type of data in your object (this works best when you have lots of strings).

    This will take more CPU time to send and to read the messages so it’s a tradeoff if you need to lower bandwidth requirements.

提交回复
热议问题