Ejemplo n.º 1
0
        private void ConnectButton_Click(object sender, EventArgs _)
        {
            if (client != null)
            {
                MessageBox.Show("Already Connected to a Chat Server!");
                return;
            }

            if (IPTB.TextLength == 0 || PortTB.TextLength == 0 || UserNameTB.TextLength == 0)
            {
                MessageBox.Show("Incomplete Binding!");
                return;
            }

            var ChatServicesURL = $"http://{IPTB.Text}:{PortTB.Text}";

            try {
                channel = GrpcChannel.ForAddress(ChatServicesURL);
                client  = new ChatServices.ChatServicesClient(channel);
                cts     = new CancellationTokenSource();
                RecvMessage(client.Join(new JoinRequest()
                {
                    Un = UserNameTB.Text
                }));
            } catch (Exception ex) {
                LeaveChat();
                MessageBox.Show(ex.Message);
            }
        }
Ejemplo n.º 2
0
        private void LeaveChat()
        {
            if (cts != null)
            {
                cts.Cancel();
            }
            if (channel != null)
            {
                channel.Dispose();
            }

            ChatTB.Clear();
            channel = null;
            client  = null;
            cts     = null;
        }