Example #1
0
 private void btnConectarChat_Click(object sender, EventArgs e)
 {
     if (buscarServidor(tbOtherChat.Text))
     {
         MessageBox.Show("Tratando de conectarse al chat");
     }
     else
     {
         pnOtherChat.Enabled = false;
         string[] conOtherChat = ExecuteQuery.getChat(tbOtherChat.Text);
         Client   client       = null;
         if (conOtherChat != null)
         {
             client = new Client(Convert.ToInt32(conOtherChat[0]), conOtherChat[1], tbOtherChat.Text);
             client.ConnectToServer();
             tbMyAlias.Text      = "";
             tbOtherChat.Text    = "";
             tbOtherChat.Enabled = true;
             client.SendRequest(typeMessage.login, "");
             clients.Add(client);
             client.AliasChat = tbOtherChat.Text;
             DGVOtherChats.Rows.Add(DGVOtherChats.RowCount.ToString().ToString(), client.AliasChat, client.Alias);
             clients.Add(client);
         }
     }
 }
Example #2
0
        private void btnInicializarChat_Click(object sender, EventArgs e)
        {
            if (!ExecuteQuery.insertChat(ExecuteQuery.getIP().ToString(), (int)NUDPort.Value, tbAliasMyChat.Text))
            {
                MessageBox.Show("Servidor ya creado");
                return;
            }
            try
            {
                server = new Server((int)NUDPort.Value, ExecuteQuery.getIP(), tbAliasMyChat.Text);
            }
            catch (Exception ex)
            {
                ExecuteQuery.deleteChat(tbAliasMyChat.Text);
                MessageBox.Show("hubo un error al crear el server, intentélo más tarde");
                return;
            }
            pnMyChat.Enabled  = false;
            DGVMyChat.Enabled = true;

            Client client = new Client(server.PORT, ExecuteQuery.getIP().ToString(), server.ALIAS);

            client.AliasChat = tbAliasMyChat.Text;
            client.ConnectToServer();
            clients.Add(client);
            client.SendRequest(typeMessage.login, "");
            DGVOtherChats.Rows.Add(DGVOtherChats.RowCount.ToString(), client.AliasChat, client.Alias);
        }
Example #3
0
 private void CHAT_FormClosing(object sender, FormClosingEventArgs e)
 {
     if (server != null)
     {
         listenerBox.Abort();
         activeClients.Abort();
         logins.Abort();
         ExecuteQuery.updateStateChat(0, server.ALIAS);
         foreach (Client client in clients)
         {
             ExecuteQuery.deleteUserToChat(client.Alias, client.AliasChat);
         }
         foreach (Client client in inactiveClients)
         {
             ExecuteQuery.deleteUserToChat(client.Alias, client.AliasChat);
         }
     }
 }
Example #4
0
 private void CHAT_Load(object sender, EventArgs e)
 {
     server = ExecuteQuery.startServer();
     if (server != null)
     {
         pnMyChat.Enabled   = false;
         NUDPort.Value      = server.PORT;
         tbAliasMyChat.Text = server.ALIAS;
         DGVMyChat.Enabled  = true;
         Client client = new Client(server.PORT, server.IP.ToString(), server.ALIAS);
         client.AliasChat = server.ALIAS;
         client.ConnectToServer();
         clients.Add(client);
         client.SendRequest(typeMessage.login, "");
         DGVOtherChats.Rows.Add(DGVOtherChats.RowCount.ToString(), client.AliasChat, client.Alias);
     }
     listenerBox   = new Thread(new ThreadStart(listenBox));
     activeClients = new Thread(new ThreadStart(activeClient));
     listenClient  = new Thread(new ThreadStart(addClientActive));
     listenClient.Start();
     listenerBox.Start();
     activeClients.Start();
 }