Hi, i want to create a client-server application using sockets on .net platform and being new to networking programming and i have a dilemma. The client will send data to server often and also the server will notify clients often. What is the best way to design it? should the server keep a thread to communicate with each client until it quits or just the clients send data to the server and it update the clients regularly(few seconds) or none of those? Some help would be great. Thanks guys. PS: The number of clients will reach thousands.
The way I did it back when I was writing a web server for a project was you have your main thread on the server that listens for new requests. Once a request comes in spawn a new thread and respond to the client from a different port. You keep that 2nd thread alive as long as your client/server are communicating. How long this is depends on many things. Will you have hundreds or thousands of clients? If so you should close the threads/ports often. But if you just have a couple clients keep them open longer.
I'm assuming the data sent to the clients is different for each client. If its the identical data then you should use UDP to broadcast that to all clients at once.
The .net solution for the kind of design you're describing is called Windows Communication Foundation, or WCF for short.
WCF allows for asynchronous callbacks, which would be one way of implementing the type of architecture you describe. I did most of my learning about WCF with the book Learning WCF, by Michele Bustamante. WCF is very extensive and I would recommend against shooting from the hip without a good reference.
That would depend. Does your application depend on the input as it comes in, can it be reduced to chunks of code, can it handle it in any order, ..., lots of things yet unknown about your situation.
Async sockets have merit, but aren't for all types of applications.
Blocking sockets also have merit, are simpler to conceptualize and implement, and have many application uses.
You need to first identify your need, that will dictate how you implement things going forward.