1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- using Microsoft.AspNet.SignalR.Client;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace XdCxRhDW.WebApi.SignalR
- {
- class Program
- {
- //static void Main(string[] args)
- //{
- // IHubProxy hub;
- // //服务端配置 Startup类中 app.MapSignalR();
- // //string url = "http://localhost:5000/signalr";
- // //服务端配置 Startup类中 app.MapSignalR("/hubs", new HubConfiguration());
- // string url = "http://localhost:5000/hubs";
- // HubConnection connection = new HubConnection(url);
- // connection.ConnectionSlow += Connection_ConnectionSlow;
- // connection.Error += Connection_Error;
- // connection.StateChanged += Connection_StateChanged;
- // ///服务端 配置 [HubName("MyTestHub")]
- // hub = connection.CreateHubProxy("MyTestHub");
- // connection.Start().Wait();
- // hub.On("addMessage", x =>
- // Console.WriteLine(x));
- // hub.On("SendClient", x =>
- // {
- // Console.WriteLine(x);
- // }
- // );
- // string groupName = Console.ReadLine();
- // hub.Invoke("Sign", groupName).Wait();
- // string sendgroupName = Console.ReadLine();
- // hub.Invoke("SameGroupMessage", sendgroupName).Wait();
- // string line = "";
- // while ((line = Console.ReadLine()) != null)
- // {
- // hub.Invoke("Send", "测试", line).Wait();
- // }
- // Console.ReadKey();
- // //connection.Stop();
- // //connection.Dispose();
- //}
- private static void Connection_StateChanged(StateChange obj)
- {
- if (obj.NewState == ConnectionState.Disconnected)
- {
- Console.WriteLine("连接状态为未连接啦");
- }
- }
- private static void Connection_Error(Exception obj)
- {
- Console.WriteLine("连接发生错误啦");
- }
- private static void Connection_ConnectionSlow()
- {
- Console.WriteLine("连接超时啦");
- }
- }
- }
|