First, as others have said, separate your game logic as much as you can, so the basic functionality will not depend too much on your communications infrastructure.
For communication, WCF can do the job. You can force your customers to send a request for a service hosted on IIS, authenticate / authenticate, and open a two-way channel, from where your service can push the results and link the start of new rounds.
As soon as one client connects, it waits for another. When this happens, it notifies the first client using the Duplex Channel callback and waits for it to be selected. Then he asks the second user, waiting for his answer. When it comes to, it notifies the result to both and restarts the game.
Going a little deeper into the implementation:
You will have a service with some operations (e.g. Register, PushDecision, if necessary). You will also define a callback interface, with operations that your service will have to click on the client (NotifyResult, RequestDecision, again, these are examples). You then create proxies for your clients that map to your service operations and implement callback operations so that they display events and raise them when the service clicks messages.
Use case:
Client A creates a proxy, calls a register on the server. The server receives the call, registers the cyclone, and stores the callback object in state. A duplex connection will be established. What does it mean? This means that (if you use PollingDuplexBinding, as you probably want), now the proxy in client A will make long polling requests to the server, checking if there is a callback message. If not, then it means long polls again. If there is, it calls the callback method in the proxy server, passing the data that the server clicks. The callback method in the proxy will typically raise an event or execute a delegate that you can select.
Client B connects (calls the register), does the same as for A, and the server, noticing that two clients are connected, requests A's response to its stored callback. This can happen during processing of a B-register call, or it can be launched to execute in a new thread (or, better, run in ThreadPool or run a new Task ) in a register B call.
Client A will receive a server callback requesting its selection. He can then notify the user and get a choice through the user interface. A new call is made on the server (for example, PushDecision). The server receives the choice of client A, requests B in the same way. After he has both answers, he calculates the result and pushes the result to the Clients.
The advantage of using Duplex channels with PollingDuplex with WPF is that since it uses long polling, there is no need to use ports other than 80.
This is by no means the final implementation, it is just a small guide to give you some ideas, and not just give you some vague advice. Of course, there can be many other ways to do this with WCF.
We can first assume that the application can only process two users at a time, and then, if you want, you can scale, which makes your service maintain some form of state with a mapping table with blocked access as another example.
Some thoughts on WCF: there is a simple way to start development using WCF using Visual Studio tools (svcutil), but I don't like this approach. You are not familiar with the WCF infrastructure, you are attached to the verbose magic with which it generates your proxies, and you lose flexibility, especially in special scenarios such as duplex polling, which you might want to use.
In another way, that is, manually creating your services and your proxies is not so difficult, and it becomes very interesting if you understand what can be done with it. In this regard, I can give you one piece of advice: do everything possible so that your proxy operations use Async Pattern based on tasks (you can see various ways to implement proxy operations here ). This will make your code much cleaner and more direct in combination with the new C # async / waitait keywords , and your user interface will be a joy to implement.
I can recommend some links to get you started. Some of them are old, but very didactic.
- There used to be a fantastic WCF article in this link , but it seems to be disabled now. Fortunately, I found the content available there in the file for this link .
- This covers your hosting options.
- WCF Infrastructure Topics: Link
- Duplex Services Topics: Link Link Link
- Async task-based themes: link link link