I am working on an “application system” where I also need to create a server application. I work in C # (.NET 4.0). The server will mainly collect data from different POS applications / clients (which should be around 50-100, but the server should also be able to handle about 200-300 clients). From a single client, the server is likely to receive about 1 KB about 100 times a day. The server basically needs to receive data, decrypt it and store it on disk. He also needs to check for changes in a specific directory to send new configurations to clients, which should not be very common.
I am new to C # and server programming, so please bear with me. I was thinking about using threadpooling and async methods (there is a good example that is used in the book “C # in a nutshell”). But I spent quite a bit of time searching for a better solution, and I found this. But multithreading brings more problems than advantages in my case. So I was thinking about even a managed server. "One process that processes each event (received connection, readable data, can write to the client, ...) in the callback." from what is an event driven web server . I think this is the best solution to my problem.
But I have no idea how to encode it, I could not find any examples of event-driven servers. As I understand it, I have to make one thread (+ 1 for the GUI), then create a TCP listener, and then somehow create events so that when the TCP listener listens for the client, the event could start and wake up the server, as well as when the data read from clients was available, he would wake the server.
Please help me to code this, I am completely lost. I know how to do this using
while(true) { check if client wants to connect accept client and add it to client list iterate through client list and check if anyone is sending data ... accept data and store it ... }
But this is not event related and wastes the processor. The server will not be very active, so I would like to make it as efficient as possible.
Some examples will really help.
Thanks for your time and answers.
ps Is it possible to use only one port for all clients?
EDIT: To clarify, I want to code an event-driven server, but I don't know how to do this, so I just made an example of what I know (client polling).