How do I send messages from server to client using SignalR Hubs

后端 未结 2 2035
小蘑菇
小蘑菇 2020-12-14 08:55

I am just starting to explore signalR and I would like to able to send messages from the server to all clients.

Here is my Hub

 using System;
using          


        
2条回答
  •  孤街浪徒
    2020-12-14 09:16

    I think it should be

     void aTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            var context = GlobalHost.ConnectionManager.GetHubContext();
            context.Clients.All.addMessage("Hello");      
        }
    

    instead. With Send you are calling the method used by the client to call the server...

提交回复
热议问题