public async Task SendMessageOneWay_FromHost_1000x() { TestMessageProcessor.Count = 0; using (var listener = new MessageListener(registry)) { using (var client = new MessageClient(registry)) { listener.ConnectionReceived += (sender, e) => { for (var i = 0; i < 1000; i++) { e.Host.SendOneWay(new TestRequestOneWayMessage()); } e.Host.Stop(); }; listener.Listen(IPAddress.Loopback, 10934); await client.ConnectAsync("localhost", 10934, CancellationToken.None); await Task.Delay(200); client.Disconnect(); } Assert.That(TestMessageProcessor.Count, Is.EqualTo(1_000)); listener.Stop(); } }
private async Task UpdateAgent(ServerAgent agent, MessageClient messageClient, CancellationToken token) { var message = new AgentUpdateRequest { Filename = UpdateFilename, }; try { await messageClient.Send(message) .GetResponseAsync(token); try { messageClient.Disconnect(); } catch {} } finally { messageClient?.Dispose(); messageClient = null; } Output.WriteBlock(block => block .Write("Agent update started on ", ConsoleColor.DarkCyan) .Write(agent.Name, ConsoleColor.Cyan) .WriteLine("...", ConsoleColor.DarkCyan)); await Task.Delay(6_000, token); var reconnectTimeout = TimeSpan.FromMinutes(2); try { messageClient = await Reconnect(agent, reconnectTimeout, token); } catch (OperationCanceledException) { throw new ApplicationException($"A timeout occurred after {reconnectTimeout} while waiting for the update to complete."); } finally { if (messageClient != null) { messageClient.Disconnect(); messageClient.Dispose(); } } }
protected override async Task OnReleaseSessionAsync(CancellationToken token) { var message = new SessionReleaseRequest { AgentSessionId = AgentSessionId, }; MessageClient.SendOneWay(message); await Task.Delay(800, token); MessageClient.Disconnect(TimeSpan.FromSeconds(30)); }
private async Task AgentAction(ServerAgent agent) { using (var messageClient = new MessageClient(PhotonServer.Instance.MessageRegistry)) { try { Output.WriteLine($"[{agent.Name}] Connecting...'", ConsoleColor.White); await messageClient.ConnectAsync(agent.TcpHost, agent.TcpPort, TokenSource.Token); await ClientHandshake.Verify(messageClient, TokenSource.Token); Output.WriteLine($"[{agent.Name}] Connected.", ConsoleColor.DarkCyan); } catch (Exception error) { using (var block = Output.WriteBlock()) { block.WriteLine($"[{agent.Name}] Connection Failed!", ConsoleColor.DarkRed); block.WriteLine(error.UnfoldMessages(), ConsoleColor.DarkYellow); } return; } var userMgr = PhotonServer.Instance.UserMgr; var securityConfig = PhotonServer.Instance.ServerConfiguration.Value.Security; var message = new SecurityPublishRequest { Users = userMgr.AllUsers.ToArray(), UserGroups = userMgr.AllGroups.ToArray(), SecurityEnabled = securityConfig.Enabled, SecurityDomainEnabled = securityConfig.DomainEnabled, }; Output.WriteLine($"[{agent.Name}] Publishing security configuration...", ConsoleColor.White); await messageClient.Send(message) .GetResponseAsync(); Output.WriteLine($"[{agent.Name}] security configuration published.", ConsoleColor.DarkGreen); try { Output.WriteLine($"[{agent.Name}] Disconnecting...", ConsoleColor.White); messageClient.Disconnect(); } catch {} } }
protected override async Task OnReleaseSessionAsync(CancellationToken token) { var message = new SessionReleaseRequest { AgentSessionId = AgentSessionId, }; MessageClient.SendOneWay(message); //.GetResponseAsync(token); MessageClient.Disconnect(TimeSpan.FromSeconds(30)); // TODO: // 1) sender sends a release message // 2) receiver sends released message // 3) flush receiver // 4) sender waits up to N seconds for response }
public async Task SendMessageOneWay_ToHost_1000x() { TestMessageProcessor.Count = 0; using (var listener = new MessageListener(registry)) { using (var client = new MessageClient(registry)) { listener.Listen(IPAddress.Any, 10934); await client.ConnectAsync("localhost", 10934, CancellationToken.None); for (var i = 0; i < 1000; i++) { client.SendOneWay(new TestRequestOneWayMessage()); } client.Disconnect(); } Assert.That(TestMessageProcessor.Count, Is.EqualTo(1_000)); listener.Stop(); } }
private void SessionClient_OnSessionRelease(RemoteTaskCompletionSource taskHandle) { Task.Run(async() => { Tasks.Stop(); if (MessageClient.IsConnected) { if (!string.IsNullOrEmpty(AgentSessionId)) { try { await OnReleaseSessionAsync(Token); } catch (Exception error) { Log.Error($"Failed to release Agent Session '{AgentSessionId}'! {error.Message}"); } } MessageClient.Disconnect(); } }, Token) .ContinueWith(taskHandle.FromTask, Token); }
public async Task ClientDisconnectWaitsForMessages() { var registry = new MessageProcessorRegistry(); registry.Register(typeof(DelayedTestProcessor)); using (var listener = new MessageListener(registry)) using (var client = new MessageClient(registry)) { listener.Listen(IPAddress.Loopback, Port); await client.ConnectAsync(Host, Port, CancellationToken.None); DelayedTestProcessor.Complete = false; var message = new DelayedTestRequest(); var _ = client.Send(message).GetResponseAsync <DelayedTestResponse>(); client.Disconnect(); //await task; Assert.That(DelayedTestProcessor.Complete, Is.True); listener.Stop(); } }
public void Stop() { Tasks.Stop(); MessageClient.Disconnect(); }