Exemple #1
0
 private void btnIniciar_Click(object sender, EventArgs e)
 {
     try
     {
         int puerto_server = Convert.ToInt32(txtPuerto.Text);
         if (Channel != null)
         {
         }
         else
         {
             Channel = new TcpChannel(puerto_server);
             if (ChannelServices.GetChannel(Channel.ChannelName) != null)
             {
             }
             else
             {
                 ChannelServices.RegisterChannel(Channel, false);
             }
         }
         RemotingConfiguration.RegisterWellKnownServiceType(typeof(Remote_Lbl.Remota), "chat", WellKnownObjectMode.Singleton);
         local = (Remota)Activator.GetObject(typeof(Remota), "tcp://localhost:" + txtPuerto.Text + "/chat");
         btnIniciar.Enabled = false;
         txtPuerto.Enabled  = false;
         timer1.Start();
         lblEstado.Text = "Estado: Corriendo...";
         lstConsola.Items.Add("Servidor Iniciado");
         btnEjecutar.Enabled = true;
         gboxCliente.Enabled = true;
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Exemple #2
0
 private void ConnectToServer(string ip_port, string username)
 {
     if (txtUser.Text != "")
     {
         Login(txtUser.Text);
     }
     else
     {
         MessageBox.Show("Ingresar un userName.");
     }
     try
     {
         if (Channel == null)                                           //verifica si el canal ya fue registrado tanto como server como por el
         {
             Channel = new TcpChannel(Convert.ToInt32(txtPuerto.Text)); //registra el canal y el puerto por el cual entramos
             ChannelServices.RegisterChannel(Channel, false);
         }
         Remota RemotedObject = (Remota)Activator.GetObject(typeof(Remota), "tcp://" + ip_port + "/chat");
         try
         {
             RemotedObject.IsInstance();
         }
         catch (Exception ex)
         {
             throw new Exception("No existe un servidor con esa ruta.");
         }
         if (RemotedObject.LivesRoom(chatUser.userName, chatUser.ip, chatUser.Puerto))  //verifica si existo
         {
             MessageBox.Show("Este userName ya esta siendo utilizado.");
         }
         else
         {
             RemotedObject.JoinChat(chatUser.userName, chatUser.ip, chatUser.Puerto); //me agrega
             remotes.Add(RemotedObject);                                              //invoca servicio remoto
             server_name.Add("tcp://" + ip_port + "/chat");                           //agrega direccio de la sala
             tiempos.Add(0);
             tbVentas.SelectedIndex = 1;
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Error a intentar acceder a un chat: " + ex.Message);
     }
 }
Exemple #3
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";
            }
        }