简体   繁体   中英

Server - Client communication WPF C#

在此处输入图片说明

I am struggling to find a solution for this WPF application.

  • There are a Server and a Client.
  • They should communicate with each other via a TCP connection.
  • If the server toggles the button 1 the color should also be changed on the client at the color of the ellipse 1.

My question is:
What datatype should I use and how will the Server send to the client the information for changing color?

There are hundreds of ways of doing this. One is a simple message queue such as RabbitMQ, ZeroMQ, MQSeries etc...

When the server needs to tell the client something it puts a message on to the queue, the Message Queue informs the client and delivers the message so the client can act on it. If you need two way you just repeat the process but in a different queue. (or with a different topic if you only want one queue).

As for the payload, your data can be whatever you like. Personally I create an object Serialize it to JSON and pass the JSON. The client would deserialize and now has the full object to work with. This way you can add additional properties to the object as needed in the future.

Also you could write a TCP Server on the server side and the the TCPClient on the client side for direct communication.

Or you could use WCF on the client and server.

Plenty of ways of doing it, all with there own benefits and drawbacks, so I would research them and choose the best one for your needs.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM