This is totally in the nature of pure client-server model: no information can be pushed. In other words, as all data is delivered only on the request from the clients, the only solution is periodic polling of the server by all clients, which is pretty bad. So, each client could periodically poll the server for information of the status of the currently present users and the chat thread(s).
You cannot improve this situation staying withing the pure client-server model. You could implement some sort of
Push Technology instead.
See:
http://en.wikipedia.org/wiki/Client-server_model[
^],
http://en.wikipedia.org/wiki/Pull_technology[
^],
http://en.wikipedia.org/wiki/Push_technology[
^].
For a more general view of the problem, see also
http://en.wikipedia.org/wiki/Inversion_of_control[
^].
[EDIT]
I'm not 100% sure you need to use sockets, but to me it looks like a reasonable choice. I would suggest you use TCP sockets and sessions, and not directly but through sockets but through a slightly higher-level classes
TcpListener
/
TcpClient
. You could actually use two channels per user: one for requests to server, another one reading from a network stream in order to implement pushing notifications from the server. Naturally, as stream operations are blocking, each of both channels will need a separate thread.
Avoid creating a separate thread per client on the server-side — this is a known fatal design mistake of some developers. The name of threads should be fixed or remain constant soon after the server runtime. A server needs one separate thread to listen to new connections and just one or two more threads common for all clients — to read/write from/to network streams in cycle by the set of clients.
I explained some sketch of the similar design in my past solutions:
Multple clients from same port Number[
^],
automatic updater triggered via server[
^].
I provided my overview of several different levels of networking, remoting or WCF:
how i can send byte[] to other pc[
^],
Communication b/w two Windows applications on LAN.[
^].
Ideally, the server part should be a Windows Service. Start here:
http://msdn.microsoft.com/en-us/library/d56de412%28v=VS.100%29.aspx[
^].
—SA