/// <summary> /// Disconnect a hub /// this will also remove all event handlers from that hub /// (TODO this behaviour will cause problems in multi client scenarios,find a workaround) /// </summary> /// <param name="me">the hub you want to disconnect from</param> public void DisconnectHub(Hub me) { lock (connected_hubs_lock) { connected_hubs.Remove(me); } me.Disconnect(); me.Ungrab(); //hub event handlers should be ungrabbed }
public void TestLocalHubConnect() { Console.WriteLine("Test to connect to a local hub (remember to start some hub before)."); bool wait = true; Hub hub = new Hub(); hub.Address = "localhost"; hub.Connected += delegate(Hub connected) { Console.WriteLine("Hub Connected"); //Assert.IsTrue(!string.IsNullOrEmpty(external_ip), "no ip address fetched"); //wait = false; }; hub.LoggedIn += delegate(Hub logged_in) { Console.WriteLine("Hub Logged in"); wait = false; }; hub.Disconnected += delegate(Hub disconnected) { if (wait) { Console.WriteLine("Test failed : Hub disconnected."); Assert.Fail("Test failed : Hub disconnected."); } }; hub.UnableToConnect += delegate(Hub error) { Console.WriteLine("Test failed : Unable to connect to"); }; hub.IsGrabbedByClient = true; hub.Connect(); Console.WriteLine("Waiting for hub events."); DateTime start = DateTime.Now; while (wait) { if (DateTime.Now - start > new TimeSpan(0, 0, 10)) { Console.WriteLine(""); Console.WriteLine("Operation took too long"); wait = false; Assert.Fail("Operation took too long"); } Console.Write("."); Thread.Sleep(250); } hub.Disconnect(); Console.WriteLine("Local Hub Connect Test successful."); }