Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static HubConnection connection = new HubConnection("http://MY HUB URL/");
- IHubProxy proxy = connection.CreateHubProxy("ChatHub");
- private void ConnectToHub()
- {
- proxy.On<int>("broadcastMessage", data =>
- {
- UpdateStatus(data.ToString());
- });
- connection.Start().ContinueWith(task =>
- {
- if (task.IsFaulted)
- {
- UpdateStatus("Not Connected");
- ConnectToHub();
- }
- else
- {
- UpdateStatus(string.Format("Success! Connected with client connection id {0}", connection.ConnectionId));
- hubuserid = connection.ConnectionId;
- LogIn();
- }
- });
- connection.Error += ex =>
- {
- UpdateStatus(string.Format("An error occurred {0}", ex.Message));
- };
- connection.Closed += () =>
- {
- UpdateStatus(string.Format("Connection with client id {0} closed", connection.ConnectionId));
- ConnectToHub();
- };
- connection.Reconnected += () =>
- {
- //LogIn();
- UpdateStatus("The connection was re-established");
- };
- }
- public MainPage()
- {
- this.InitializeComponent();
- this.NavigationCacheMode = NavigationCacheMode.Required;
- ConnectToHub();
- }
- if (task.IsFaulted)
- {
- UpdateStatus("Not Connected");
- ConnectToHub();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement