ASP.NET Chat – Push Response to User for Created Request in Asp.Net Chat Server

asp.netcchat

I am working on a Chat Server Application in Asp.Net with C#.

Suppose there are 5 users online say User A,B,C,D,E. Suppose A sends a message in chatbox to user B, so how the chatbox (Textbox/Textarea of chat) of User B will load the new content?

One Option is to refresh the chatbox every 10Seconds or 15 seconds but it's pretty unuseful way because as if there is no new message for the user the chatbox will still be refreshed.


I have an aspx page say client.aspx with client.aspx.cs as code behind file and server file say server.cs.
There is a send button on aspx page on click event of this button i called a method of my server file say UpdateChatbox(from,to,content) now the from is User A, to is User B and content is my msg in chatbox,
Now the question is :
How Server.cs file update the ChatBox on client.aspx page of User B?

Best Answer

SignalR is what you are looking for.

From the website:

ASP.NET SignalR is a new library for ASP.NET developers that makes developing real-time web functionality easy. SignalR allows bi-directional communication between server and client. Servers can now push content to connected clients instantly as it becomes available. SignalR supports Web Sockets, and falls back to other compatible techniques for older browsers. SignalR includes APIs for connection management (for instance, connect and disconnect events), grouping connections, and authorization.

You can have a look inside JabbR source code to see what it can do and how to do it.