public ClienteGT(string host, string port, SmallKeyboard.frmKeyboard f,string l) { this.form = f; this.login = l; // Set up GT client = new Client(new DefaultClientConfiguration()); // client.ErrorEvent += es => Console.WriteLine(es); client.ErrorEvent += es => MessageBox.Show(es.ToString()); // Evento do client client.ConnexionRemoved += client_ConnexionRemoved; client.Start(); // Evento do client client.MessageSent += new MessageHandler(this.MensagemEnviada); // updates: controle de acesso à sessão updates = client.OpenSessionChannel(host, port, SessionUpdatesChannelId,ChannelDeliveryRequirements.SessionLike); // Evento do updates updates.MessagesReceived += updates_SessionMessagesReceived; // Utilizar o OpenObjectChannel para enviar objetos genéricos objts = client.OpenObjectChannel(host, port, ObjectChannelId, ChannelDeliveryRequirements.CommandsLike); objts.MessagesReceived += new Action<IObjectChannel>(objts_MessagesReceived); }
public bool SetaUser(String login,String senha) { try { this.lo = login; this.pass = senha; // O primeiro objeto a ser enviado é uma string que vai indicar // ao servidor se eh uma conexão para trocas de objetos no nível do // GEF ou nível do ArgoUML. Devo enviar também o login e a senha ArrayList l = new ArrayList(); l.Add(this.lo); // l.Add(this.pass); // this.EnviaEvento(l,"ARGO"); // Aqui efetivamente envia os dados! Byte[] ByteGet; ByteGet = getByteArrayWithObject((Object) objAenviar[0]); socket.Send(ByteGet, ByteGet.Length, 0); objAenviar.Clear(); // Recebendo a resposta byte[] bytes = new byte[1024]; int bytesRec = socket.Receive(bytes); ArrayList list = (ArrayList) getObjectWithByteArray(bytes); Object o = list[0]; String nomeEvento = (String) list[1]; if (nomeEvento.Equals("ERRO")) { MessageBox.Show("Login ou senha incorretos!" , Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Warning); return false; } else { // Aqui vou armazenar as informações que vão ser colocadas na tabela! if (nomeEvento.Equals("PROT_lista_sessoes")) { ArrayList se = (ArrayList) o; // Colocando os nomes das sessões colaborativas this.listaSessoes = se; // Agora colocando a cor do telepointer String id = (String) list[2]; Color c = (Color) list[3]; this.setaCorTelepointer(c); this.setaIdTelepointer(id); // Aqui adiciono o usuário e sua cor no ArrayList de usuários! // O armazenamento será feito em um ArrayList que contém arrays de strings (string[]) string[] info = new string[2]; info[0] = this.lo; info[1] = c.Name; this.Form.aUsers.Add(info); // Adicionando o usuário no listview System.Windows.Forms.ListViewItem listViewItem = new System.Windows.Forms.ListViewItem(new string[] { this.lo.Trim()}, -1, System.Drawing.SystemColors.WindowText, c , new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)))); listViewItem.StateImageIndex = 0; listViewItem.Checked = true; listViewItem.Tag = this.lo.Trim(); this.Form.listView1.Items.Add(listViewItem); this.Form.listView1.Refresh(); } // Iniciando a Thread que vai receber os dados this.cr = new ClienteRecebe(socket); this.cr.Form = this.Form; ThreadStart threadDelegate = new ThreadStart(this.cr.run); tClienteRecebe = new Thread(threadDelegate); tClienteRecebe.Start(); // Iniciando a Thread... // Aqui vou colocar a chamada para o cliente GT! cGT = new ClienteGT(this.serverName, "9999",this.Form, this.lo); cGT.client.Update(); return true; } } catch (Exception e) { MessageBox.Show("Exception in ClienteConecta " + e.Message , Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Warning); return false; } }