Note that there are some explanatory texts on larger screens.

plurals
  1. POHelp with event driven TCP server
    primarykey
    data
    text
    <p>I'm working on an "application system" , where I also need to make a server application. I'm working 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 be capable of handling also around 200-300 clients). From a single client a server will probably receive around 1KB about 100x times a day. The server mainly needs to accept the data, decrypt it and store it to disk. It should also check for changes in specific directory in order to send new configurations to clients, which shouldn't be very often.</p> <p>I'm quite new to C# and server programming so please bear with me. I thought about using threadpooling and async methods (there is a nice example using that in a book "C# in a nutshell"). But I spend quite some time looking for best solution and I found this. But multithreading brings more problems than benefits in my case. Thus I thought about even driven server. "A single process, handle every event (accepted connection, data available to read, can write to client, ...) on a callback." from " <a href="https://stackoverflow.com/questions/3981566/what-is-event-driven-web-server/3982440#3982440">what is event driven web server</a>". I find that the best solution to my problem.</p> <p>But I have no idea on how to code it, I couldn't find any examples about event driven servers. As far as I understand it I should make one thread (+ 1 for GUI), then create a TCP listener and then somehow create events so that when TCP listener could accept a client the event would fire and wake up the server, also when data to read from clients would be available it would wake up the server. </p> <p>Please help me out to code this, I'm totally lost. I know how I could do this using</p> <pre><code>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 ... } </code></pre> <p>But that is not event driven and is wasting CPU. Server will not be very active, so I'd like to make it as efficient as possible.</p> <p>Some examples would really help.</p> <p>Thank you for your time and answers.</p> <p>p.s. Can I use just one port for all the clients?</p> <p><strong>EDIT:</strong> To clarify, I want to code an event driven server, but I don't know how to, thus I just made an example of what I know (client polling).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload