终端一体化运控平台
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 

40 行
1.1 KiB

  1. using Microsoft.AspNetCore.SignalR.Client;
  2. namespace BPASmartClient.HubHelper
  3. {
  4. public class HubHelper
  5. {
  6. private volatile static HubHelper _Instance;
  7. public static HubHelper GetInstance => _Instance ?? (_Instance = new HubHelper());
  8. private HubHelper() { }
  9. public Action<object> Report { get; set; }
  10. public Action<object> Upstreamrequest { get; set; }
  11. HubConnection hubConnection;
  12. public void Connect(string ip, int port)
  13. {
  14. hubConnection = new HubConnectionBuilder().WithAutomaticReconnect().WithUrl($"http://{ip}:{port}/personhub").Build();//连接
  15. hubConnection.On<object>("Report", (s) => { Report?.Invoke(s); });
  16. hubConnection.On<object>("Upstreamrequest", (s) => { Upstreamrequest?.Invoke(s); });
  17. try
  18. {
  19. hubConnection.StartAsync();
  20. }
  21. catch (Exception ex)
  22. {
  23. throw;
  24. }
  25. }
  26. public void SendMessage(string info)
  27. {
  28. hubConnection.SendAsync("Send", info);
  29. }
  30. }
  31. }