As an example, we will write a primitive chat with instant notification of all customers using the SignalR library .
training
To do this in Visual Studio we will create an empty ASP.NET project Empty Web Application
The SignalR library itself is added to one line via NuGet: ')
Install-Package SignalR This will add jQuery and SignalR scripts to the project, as well as a reference link to the SignalR dll and other dlls necessary for its work.
write server code
Add an arbitrary class - I will call it Chat, it must inherit from the Hub class defined in SignalR.Hubs
In our class, you can define any number of any public methods, with any parameters - all of them are available from the appropriate JavaScript proxy class on the client.
In our case, we define a simple Send, and for convenience, the parameter will be dynamic.
Clients defined in the parent class, is a dynamic object — a call to any arbitrary method on it — calls it on all connected clients with the same parameters.
write client code
we add to the html project a document - chat.html, with a simple markup