Exemple #1
0
        public Chat(bool isClient, string hostIpvar, string username, AsynchronousSocketListener lmao)
        {
            InitializeComponent();
            ListBox.CheckForIllegalCrossThreadCalls = false;

            lmao.SetChatInstance(this);
            this.isClient  = isClient;
            this.hostIpvar = hostIpvar;
            this.username  = username;

            if (isClient)
            {
                hostIp.Text = hostIpvar;
            }
            else
            {
                hostIp.Text = Utils.GetLocalIPAddress();
            }

            client = new Client(hostIpvar, username, lmao);
            if (client != null)
            {
                string textToShow = "Conectando al servidor: " + hostIp;
                MessageBox.Show(textToShow, "Esperando host", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }
Exemple #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (username.TextLength == 0 || username.ToString() == "")
            {
                MessageBox.Show("Nombre de usuario no puede estar vacío (subnormal)", "Subnormal",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                if (client.Checked && hostIp.TextLength == 0)
                {
                    MessageBox.Show("La direccion de host no puede ser nula", "Failed to connect",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    AsynchronousSocketListener asyncronous = new AsynchronousSocketListener();
                    if (server.Checked)
                    {
                        asyncronous.StartListening();
                    }

                    string ip = hostIp.Text;
                    if (ip == "")
                    {
                        ip = GetLocalIPAddress();
                    }
                    Chat chat = new Chat(!server.Checked, ip, username.Text, asyncronous);
                    chat.Show();
                }
            }
        }
Exemple #3
0
 public Client(string ip, string username, AsynchronousSocketListener listener)
 {
     this.AsListener = listener;
     this.ip         = ip;
     ClientSocket    = ConnectToHost(ip);
     Send("USR_" + username);
     //performListen(ClientSocket);
 }