void Disconnect(ref ComClient client) { bool connected = true; Stopwatch sw = new Stopwatch(); client.OnDisconnected += (node) => { connected = false; }; client.Disconnect(); sw.Start(); while (true) { if (!client.IsConnected && !connected) { break; } else if (sw.Elapsed.Seconds >= 3) { client.Close(); throw new TimeoutException(); } Task.Delay(100); } sw.Stop(); client.Close(); }
public MainWindow() : base(Gtk.WindowType.Toplevel) { Build(); buttonSend.Clicked += (sender, e) => { if (textviewInput.Buffer.Text.Length > 0) { client.Send(0, textviewInput.Buffer.Text); textviewInput.Buffer.Text = ""; } }; buttonConnect.Clicked += (sender, e) => { if (client.IsConnected) { client.Disconnect(); } else { client.Connect("127.0.0.1"); } }; client.OnConnected += (node) => { textviewInput.Sensitive = true; buttonSend.Sensitive = true; buttonConnect.Label = "Disconnect"; }; client.OnDisconnected += (node) => { textviewInput.Sensitive = false; buttonSend.Sensitive = false; buttonConnect.Label = "Connect"; }; client.AddChannel(new DataChannel <string>(0, QosType.Reliable, Compression.LZ4, Encryption.Aes, (endPointIp, data) => { OnReceive(data); })); client.ListenPortNumber = client.PortNumber + 1; client.Open(); client.AcceptBeacon = true; }