问题
I have Client/Server System (using Socket) with multiple clients and single server, which is sending xml datas every seconds on all clients.
The XML datas are always in different size between 1 - 18000 characters and server needs to send these XML-Datas to all clients at the same time.
Now I want to know, how to make the communication between the server and clients faster.
Maybe I will ask more then one Question, but I am really stucked at this point and I can't continue anymore.
- Should I compress every XML-Data before sending?
- Should I serialize the XML-Datas? (maybe the xml data size will be decreased)
- Do I need to convert every XML-Datas into byte[] array(for buffer), because the communication must be done at the sametime for all clients.
Thank You!
回答1:
You could use a middle layer with built in pub-sub topology if you are currently iterating through your connected clients. 0MQ has the ability for a single publisher to send to n subscribers very efficiently and has a C# binding. You could also compress the messages before being sent as you suggested.
回答2:
If you are using WCF
you can easily integrate GZip compression.
check here: WCF Compression over HTTP sample
回答3:
Assuming you work on an intranet, I would recommend to multicast your xml data. That way, your server would send a single copy of xml data every second (instead of sending N copies of data for N client)
来源:https://stackoverflow.com/questions/7922206/using-gzipstream-for-client-server-async-communication