private void btnOK1_Click(object sender, EventArgs e) { if (this.conectado == true) { try { Protocolo msgToSend = new Protocolo(); msgToSend.strElemento = this.cbJanelas.Text; string acao1 = this.cbAcao1.Text; if (acao1 == "Abrir") msgToSend.cmdAcao = Acao.Abrir; if (acao1 == "Fechar") msgToSend.cmdAcao = Acao.Fechar; if (acao1 == "Travar") msgToSend.cmdAcao = Acao.Travar; byte[] byteData = msgToSend.ToByte(); this.clientSocket.BeginSend(byteData, 0, byteData.Length, SocketFlags.None, new AsyncCallback(OnSend), null); } catch (Exception) { MessageBox.Show("Não foi possível efetuar o comando!", "ClienteA", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void Disconnect() { try { if (this.conectado == true) { try { Protocolo msgToSend = new Protocolo(); msgToSend.strMensagem = null; msgToSend.strElemento = null; msgToSend.cmdAcao = Acao.Desconectar; byte[] b = msgToSend.ToByte(); this.clientSocket.Send(b, 0, b.Length, SocketFlags.None); this.clientSocket.Disconnect(false); this.clientSocket.Close(); } catch (ObjectDisposedException) { } catch (Exception ex) { MessageBox.Show(ex.Message, "ClienteA FormClosing", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } catch (Exception ex) { MessageBox.Show(ex.Message, "ClienteA Disconnect", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { this.conectado = false; } }