Previously used two times signalr, but there was a period of time did not get, today re-get, found that has forgotten almost, make a note!
Create a console project first
NuGet Add Reference Online Search:
Microsoft.AspNet.SignalR.SelfHost
Microsoft.Owin.Cors
Add code in Program.cs
Add a Hub
In this hub, we've got a connection. When the server pushes a message like a client, the client receives the method as receive
Next I added a Send method to the hub, the client sends the message when the message will be broadcast to all clients, the code is as follows:
public void Send (String msg) { Clients.All.receive (msg); }
Let's test the Web side first:
Create an empty web MVC project (WinForm is OK), NuGet add search SignalR Add: Reference to Microsoft ASP. SignalR JavaScript Client
Create a homecontroller that is referenced in its index.cshtml, respectively: jquery,jquery.signalr.xxx.min.js
Add JS Reference and JS code
Note the two HTTP address references, be sure to write the address of your service point with the port, next we test the effect:
From the above we can see that no matter which connection to the server, send the message, all the clients can receive, if you want to send a message for a separate person, only need to specify the person's ClientID can
SIGNALR will not save the client information, do not know if the person is connected to the end, so to achieve online offline function, maintain an online cache table!
Click here to download
SignalR Selfhost Real-time messaging, integrated into the Web for server message push