1

Here is simple SignalR app example: https://github.com/SignalR/SignalR/wiki/QuickStart-Hubs

I've got this class

  public class Chat : Hub 
  {
       public void Send(string message)
      {
          // Call the addMessage method on all clients            
          Clients.All.addMessage(message);
      }
  }

But I don't create an object anywhere by myself so I don't know how to call Send from server side?

There is a way by using

HubConnection("http://localhost/mysite") -> chat.Invoke("Send", line).Wait();

But it's looking for me a bit overhead. My main task it to provide an event coming from server to client side so is it possible to make it without using Microsoft.AspNet.SignalR.Client and HubConnection ?

4

1 回答 1

3

You don't necessarily need to call your Hub Send method from outside of the hub itself. Instead do this:

GlobalHost.ConnectionManager.GetHubContext<Chat>().Clients.All.addMessage(message)
于 2013-03-04T05:53:25.233 回答