private async void MainForm_Load(object sender, EventArgs e) { await Task.Delay(3000); _connection = new HubConnectionBuilder() .WithUrl("http://localhost:5000/hub") .Build(); _connection.On <int, int, int>("ReceiveKeys", async(q, a, yb) => { var xc = DiffieHellmanService.GetX(q); var yc = DiffieHellmanService.GetY(a, xc, q); _key = DiffieHellmanService.GetKey(yb, xc, q); await _connection.InvokeAsync("ReceiveKey", (int)yc); UserNameTextBox.Enabled = true; MessageTextBox.Enabled = true; SendButton.Enabled = true; }); _connection.On <string, string>("Chat", (name, message) => { ChatTextBox.Font = new Font(ChatTextBox.SelectionFont, FontStyle.Bold); ChatTextBox.AppendText($"{name}: {message}"); ChatTextBox.AppendText("\n"); }); await _connection.StartAsync(); await _connection.InvokeAsync("GetKeys"); }
public async Task GetKeys() { var q = DiffieHellmanService.GetQ(); var a = DiffieHellmanService.GetA(q); var x = DiffieHellmanService.GetX(q); var y = DiffieHellmanService.GetY(a, x, q); var keys = new Keys(q, a, x, y); _keys.TryAdd(Context.ConnectionId, keys); await Clients.Caller.SendAsync("ReceiveKeys", q, a, (int)y); }