Example #1
0
        private void Disconnect(string ip_port)
        {
            try
            {
                for (int i = 0; i < server_name.Count; i++)
                {
                    if (server_name[i] == "tcp://" + ip_port + "/chat")
                    {
                        if (remotes[i].LivesRoom(chatUser.userName))
                        {
                            remota.SendMgsToSvr(chatUser.userName + " a salido del chat.", "");
                            remotes[i].LeaveChat(chatUser.userName, chatUser.ip, chatUser.Puerto);
                            server_name.RemoveAt(i);
                            remotes.RemoveAt(i);
                            MessageBox.Show("Adios!!");
                        }
                        else
                        {
                            server_name.RemoveAt(i);
                            remotes.RemoveAt(i);
                            MessageBox.Show("Ya no esta en la sala.");
                        }

                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Example #2
0
        private void JoinToRoom()
        {
            try
            {
                for (int i = 0; i < remotes.Count; i++)
                {
                    lstOnlineUsers.DataSource = remotes[i].UsersOnline();
                    lblUser.Text = chatUser.userName;
                    remota       = remotes[i];
                    List <string> buzon_aux;
                    try
                    {
                        buzon_aux = remota.PostMsg(chatUser.userName);
                        foreach (string c in buzon_aux)
                        {
                            string[] orden = c.Split(',');
                            if (orden.Length == 3)
                            {
                                if (orden[0] == "File")
                                {
                                    if (orden[2] != chatUser.userName)
                                    {
                                        remota.Imbox(directory(orden[1]) + "\r\n\r\n", orden[2]);
                                    }
                                }
                                rtbChat.Text += (orden[2] + " te ha pedido un directorio.\r\n");
                            }
                            else if (c == "eliminado")
                            {
                                remota.SendMgsToSvr(chatUser.userName + " a salido del chat.", "");
                                remotes[i].LeaveChat(chatUser.userName, chatUser.ip, chatUser.Puerto);
                                remotes.RemoveAt(i);
                                server_name.RemoveAt(i);


                                MessageBox.Show("Has sido eliminado del chat.");
                                lstOnlineUsers.DataSource = null;
                                rtbChat.Text           = "";
                                tbVentas.SelectedIndex = 0;
                            }
                            else
                            {
                                rtbChat.Text += (c + "\r\n");
                            }
                        }
                        tiempos[i] = 0;
                    }
                    catch (Exception)
                    {
                        if (tiempos[i] >= 4)
                        {
                            server_name.RemoveAt(i);
                            remotes.RemoveAt(i);
                            tiempos.RemoveAt(i);
                            i--;
                            MessageBox.Show("Se perdio la conexion con el servidor ");
                        }
                        else
                        {
                            try
                            {
                                remotes[i].IsInstance();
                                if (remotes[i].LivesRoom(chatUser.userName))
                                {
                                }
                                else
                                {
                                    remotes[i].JoinChat(chatUser.userName, chatUser.ip, chatUser.Puerto);
                                }
                            }
                            catch (Exception)
                            {
                                rtbChat.Text += "Fallo en coneccion: " + server_name[i] + " se esta tratando de reconectar\r\n";
                            }
                            tiempos[i]++;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                rtbChat.Text += "Fallo de conexion " + " se esta tratando de reconectar\r\n";
            }
        }