protected async override void OnAppearing() { base.OnAppearing(); try { string path = "ws://localhost:5009/signal/xamhub"; output.Text = "Starting Test"; var client = new XamHubClient(path); await client.Connect(true); Assert(client.IsConnected, "client1 did not connect"); var client2 = new XamHubClient(path); await client2.Connect(true); Assert(client2.IsConnected, "client2 did not connect"); int counter = 0; client.OnMessage += (s) => { counter++; }; client2.OnMessage += (s) => { counter++; }; await client.SendAll("Hello"); await client.SendOthers("Hello"); await client2.SendAll("Hello"); await client2.SendOthers("Hello"); await Task.Delay(1000); Assert(counter == 6, "client did get messages " + counter); await client.DisposeAsync(); Assert(!client.IsConnected, "client1 did not disconnect"); await client2.DisposeAsync(); Assert(!client2.IsConnected, "client2 did not disconnect"); } catch (Exception ex) { Console.WriteLine(ex.Message); output.Text = ex.Message; output.TextColor = Color.Red; } }
public async Task Test1() { string path = "ws://localhost:5009/signal/xamhub"; var client = new XamHubClient(path); await client.Connect(true); Assert.IsTrue(client.IsConnected); var client2 = new XamHubClient(path); await client2.Connect(true); Assert.IsTrue(client2.IsConnected); int counter = 0; client.OnMessage += (s) => { counter++; }; client2.OnMessage += (s) => { counter++; }; await client.SendAll("Hello"); await client.SendOthers("Hello"); await client2.SendAll("Hello"); await client2.SendOthers("Hello"); await Task.Delay(1000); Assert.IsTrue(counter == 6); await client.DisposeAsync(); Assert.IsTrue(!client.IsConnected); await client2.DisposeAsync(); Assert.IsTrue(!client2.IsConnected); }