public IEnumerator Connect() => RunAsync(async() => { transport1.ConnectAsync(Arg.Any <Uri>()) .Returns(Task.FromException <IConnection>(new PlatformNotSupportedException("Invalid protocol"))); // transport2 gives a connection transport2.ConnectAsync(Arg.Any <Uri>()) .Returns(Task.FromResult(conn2)); IConnection accepted1 = await transport.ConnectAsync(new Uri("tcp4://localhost")); Assert.That(accepted1, Is.SameAs(conn2)); });
public async Task Start() { if (SystemInfo.graphicsDeviceType == GraphicsDeviceType.Null) { return; } Connecting = true; try { clientToListenConnection = await transport.ConnectAsync(new Uri(listServerUrl)); Connecting = false; Connected = true; InvokeRepeating(nameof(Tick), 1f, 1f); var buffer = new MemoryStream(); while (await clientToListenConnection.ReceiveAsync(buffer)) { ParseMessage(buffer.ToArray()); buffer.SetLength(0); } } finally { Connecting = false; Connected = false; clientToListenConnection.Disconnect(); clientToListenConnection = null; } }
public async Task Start() { gameServerToListenConnection = await transport.ConnectAsync(new System.Uri(listServerUrl)); // Update once a second. no need to try to reconnect or read data // in each Update call // -> calling it more than 1/second would also cause significantly // more broadcasts in the list server. InvokeRepeating(nameof(Tick), 0, 1); }