Ejemplo n.º 1
0
        private void ConnectButton_Click(object sender, EventArgs e)
        {
            if (services != 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 = $"tcp://{IPTB.Text}:{PortTB.Text}/OptyChatServices";

            try {
                ChannelServices.RegisterChannel(channel, false);
                services = (ChatServices)Activator.GetObject(typeof(ChatServices), ChatServicesURL);
                services.Join(UserNameTB.Text, proxy.MessageArrivedProxy);
            } catch (Exception ex) {
                services = null;
                ChannelServices.UnregisterChannel(channel);
                MessageBox.Show(ex.Message);
            }
        }
Ejemplo n.º 2
0
 private void LeaveChat()
 {
     if (services != null)
     {
         services.Leave(UserNameTB.Text, proxy.MessageArrivedProxy);
         services = null;
         ChannelServices.UnregisterChannel(channel);
     }
 }
Ejemplo n.º 3
0
        private void SendButton_Click(object sender, EventArgs e)
        {
            if (services == null)
            {
                MessageBox.Show("Connect to a Chat Server!");
                return;
            }

            if (MessageTB.Text.Length == 0)
            {
                MessageBox.Show("Invalid Message (Len == 0)!");
                return;
            }

            try {
                services.SendMessage(UserNameTB.Text, MessageTB.Text);
                MessageTB.Clear();
            } catch (Exception ex) {
                services = null;
                ChannelServices.UnregisterChannel(channel);
                MessageBox.Show(ex.Message);
            }
        }