Advertisement
Guest User

Untitled

a guest
Nov 21st, 2014
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. static HubConnection connection = new HubConnection("http://MY HUB URL/");
  2. IHubProxy proxy = connection.CreateHubProxy("ChatHub");
  3.  
  4. private void ConnectToHub()
  5. {
  6. proxy.On<int>("broadcastMessage", data =>
  7. {
  8. UpdateStatus(data.ToString());
  9. });
  10.  
  11. connection.Start().ContinueWith(task =>
  12. {
  13. if (task.IsFaulted)
  14. {
  15. UpdateStatus("Not Connected");
  16. ConnectToHub();
  17. }
  18. else
  19. {
  20. UpdateStatus(string.Format("Success! Connected with client connection id {0}", connection.ConnectionId));
  21. hubuserid = connection.ConnectionId;
  22. LogIn();
  23. }
  24. });
  25.  
  26.  
  27. connection.Error += ex =>
  28. {
  29. UpdateStatus(string.Format("An error occurred {0}", ex.Message));
  30. };
  31. connection.Closed += () =>
  32. {
  33. UpdateStatus(string.Format("Connection with client id {0} closed", connection.ConnectionId));
  34. ConnectToHub();
  35. };
  36. connection.Reconnected += () =>
  37. {
  38. //LogIn();
  39. UpdateStatus("The connection was re-established");
  40. };
  41. }
  42.  
  43. public MainPage()
  44. {
  45. this.InitializeComponent();
  46. this.NavigationCacheMode = NavigationCacheMode.Required;
  47. ConnectToHub();
  48. }
  49.  
  50. if (task.IsFaulted)
  51. {
  52. UpdateStatus("Not Connected");
  53. ConnectToHub();
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement