Networked Client-Server application advice
c#, networking, tcp
Solution
My 1st advice would be to forget about TCP/IP and sockets here. You definitely can do it with that technology stack, but you would also get a lot of headache implementing all the things you want. And the reason is it too low level technology for such a class of tasks. I would go with tcp/ip and sockets only for academic interest, or if I need tremendous control over the communication, or if I have very high performance requirements.
So, my 2nd advice would be to look at WCF technology. Don't be afraid if you haven't used it before. It's not that difficult. And if you were ready to use sockets for your app, you can handle WCF definitely. For you task you can create basic communication withing 1-2 hours from scratch using any WCF tutorial.
So, I would create a server WCF service which will have some API functions containing your business logic. It can be hosted within a windows service, IIS, or even a console application. And your clients would use that WCF service, calling their functions like it's functions from another local class in your project. WCF could also help you do the events which you want (it's a little bit more advanced topic though). And you can even forget about threading here, most of the things will be working out of the box.
Problem
I'm trying to design an application that will allow two users over a network to play the prisoner's dilemma game (http://en.wikipedia.org/wiki/Prisoner%27s_dilemma). Basically, this involves: - Game starts (Round 1). - Player 1 chooses to either cooperate, or betray. - Player 2 chooses to either cooperate, or betray. - Each other's decisions are then displayed - Round 2 begins - Etc. I've done some thinking and searching and I think the application should contain the following: - Server class that accepts incoming tcp/ip connections - Gui clients (Seperate program) - For each connection (maximum 2) the server will create a new ConnectedClient class. This class will contain the details of the two player's machines/identities. - The Server class and the ConnectedClient class will connect/subscribe events to each so they can alert one another when e.g. server instruction ready to transmit to players, or players have transmitted their inputs to the server. I'm not sure whether the best approch is to use a single thread to do or the work, or have it multithreaded. Single threaded would obviously be easier, but I'm not sure whether it is possible for this situation - I've never made a application before requiring TCP/IP connections, and I'm not sure if you can listen for two incoming connections on one thread. I've found the following guide online, but it seems that it opens two clients on two threads, and they communicate directly to each other - bypassing the server (which I will need to control the game logic): http://www.codeproject.com/Articles/429144/Simple-Instant-Messenger-with-SSL-Encryption-in-Cs I'm very interested and would be grateful on any advice on how you would go about implementing the application (mainly the server class). I hope I've explained my intentions clearly. Thanks in advance.