Click here to Skip to main content
15,910,980 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I develop a software about client server chat application using http://csharp.net-informations.com/communications/csharp-chat-client.htm[^]

When new user connect to the server, old users don't get any information about new user logging. So I want to change my project as fulfil that condition.Due to I'm new to the socket programming I haven't a clear idea about it. So, If anybody can help me, It's very grateful.

Thank You.
Posted
Updated 30-Aug-11 18:41pm
v3

1 solution

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
 
Share this answer
 
v4
Comments
Jeremy Shin Woo 31-Aug-11 0:45am    
@SA- Thanks. I'll try
Sergey Alexandrovich Kryukov 31-Aug-11 2:34am    
You are welcome. I got some more time for you to provide much more detailed advice. Please see the updated solution, after [EDIT].

If you agree that it all makes sense, please accept the answer formally (green button) -- thanks.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900