终端一体化运控平台
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 

40 righe
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. }