Пример #1
0
        static void Main(string[] args)
        {
            string url = "http://*:8089";
            using (WebApp.Start(url))
            {
                Console.WriteLine("Server running on {0}", url);
                while (true)
                {
                    string key = Console.ReadLine();
                    if (key.ToUpper() == "W")
                    {
                        IHubContext hubContext = GlobalHost.ConnectionManager.GetHubContext<MyHub>();
                        hubContext.Clients.All.addMessage("server", "ServerMessage");
                        Console.WriteLine("Server Sending addMessage\n");
                    }
                    if (key.ToUpper() == "E")
                    {
                        IHubContext hubContext = GlobalHost.ConnectionManager.GetHubContext<MyHub>();
                        hubContext.Clients.All.heartbeat();
                        Console.WriteLine("Server Sending heartbeat\n");
                    }
                    if (key.ToUpper() == "R")
                    {
                        IHubContext hubContext = GlobalHost.ConnectionManager.GetHubContext<MyHub>();

                        var vv = new HelloModel { Age = 37, Molly = "pushed direct from Server " };

                        hubContext.Clients.All.sendHelloObject(vv);
                        Console.WriteLine("Server Sending sendHelloObject\n");
                    }
                    if (key.ToUpper() == "L")
                    {
                        /*foreach (var data in UserHandler.ConnectedIds.ToList())
                        {
                            Console.WriteLine(data.ToString());
                        }*/

                        Console.WriteLine(UserHandler.ConnectedIds.Count.ToString());

                    }
                    if (key.ToUpper() == "C")
                    {
                        break;
                    }
                }

                Console.ReadLine();
            }
        }
Пример #2
0
 public void SendHelloObject(HelloModel hello)
 {
     Console.WriteLine("Hub hello {0} {1}\n", hello.Molly, hello.Age);
     Clients.All.sendHelloObject(hello);
 }