using Microsoft.AspNet.SignalR; using Microsoft.AspNet.SignalR.Hosting.Memory; var host = new MemoryHost(); host.MapHubs(); var connection = new HubConnection(host.Url); var proxy = connection.CreateHubProxy("MyHub"); await connection.Start();
using Microsoft.AspNet.SignalR; using Microsoft.AspNet.SignalR.Hosting.Memory; public class MyHub : Hub { public void SendMessage(string message) { Clients.All.ReceiveMessage(message); } } var host = new MemoryHost(); host.MapHubs(); var connection = new HubConnection(host.Url); var proxy = connection.CreateHubProxy("MyHub"); proxy.OnThis example creates a simple "MyHub" hub that sends a message to all clients, and starts a connection to it in an in-memory host. The client then calls the "SendMessage" method on the hub, which triggers the hub to send a message to all connected clients. The client then receives this message through the "ReceiveMessage" event.("ReceiveMessage", message => { Console.WriteLine(message); }); await connection.Start(); proxy.Invoke("SendMessage", "Hello, world!");