public void Send(string name, string message) { var myViewModel = new MyViewModel { Message = message, Name = name }; Clients.Client(Context.ConnectionId).addMessage(JsonConvert.SerializeObject(myViewModel)); }
public void Notify(string message) { var myViewModel = new MyViewModel { Message = message, Name = "" }; Clients.All.addMessage(JsonConvert.SerializeObject(myViewModel)); }
static void Main(string[] args) { // This will *ONLY* bind to localhost, if you want to bind to all addresses // use http://*:8080 to bind to all addresses. // See http://msdn.microsoft.com/en-us/library/system.net.httplistener.aspx // for more information. string url = "http://localhost:8080"; using (WebApp.Start(url)) { Console.WriteLine("Server running on {0}", url); Console.ReadLine(); var myViewModel = new MyViewModel { Message = "hello", Name = "name" }; dynamic thing = GlobalHost.ConnectionManager.GetHubContext<MyHub>(); thing.Notify("asdasdasdasdasd"); Console.ReadLine(); } }