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; }
void Connect(ref ComClient client) { bool connected = false; Stopwatch sw = new Stopwatch(); client.SetBeaconAcceptFunction((data) => { if (data == "Test") { return(true); } else { return(false); } }); client.OnConnected += (node) => { connected = true; }; client.Open(); client.AcceptBeacon = true; //server.Server.BeaconStart(); //server.Server.SendConnectBeacon("127.0.0.1"); client.Connect("127.0.0.1"); sw.Start(); while (true) { if (client.IsConnected && connected) { break; } else if (sw.Elapsed.Seconds >= 3) { client.Close(); server.Server.BeaconStop(); throw new TimeoutException(); } Task.Delay(100); } sw.Stop(); }