// disconnection with server private void ToolStripMenuItemDisconnection_Click(object sender, EventArgs e) { if (client != null && client.Connected()) { toolStripStatusLabel1.BackColor = Color.Red; toolStripStatusLabel1.Text = "Connection with " + client.RemoteEndPoint() + " is broken"; textBoxTextTransmission.Clear(); textBoxHashedText.Clear(); textBoxInformation.Clear(); InvisibleFields(); client.Close(); } else { MessageBox.Show("No connection to the server"); } }
//connection by host name with server private void ToolStripMenuItemByHostName_Click(object sender, EventArgs e) { FormConnection connection = new FormConnection(); connection.label1.Text = "Enter name remote host:"; connection.ShowDialog(); string hostName = connection.host; if (hostName != "") { try { IPHostEntry ipAll = Dns.Resolve(hostName); IPAddress ip = ipAll.AddressList[0]; client = new Client(); client.Connect(ip); if (client.Connected()) // change status label if have connection with server { toolStripStatusLabel1.BackColor = Color.Lime; toolStripStatusLabel1.Text = "Connected with " + client.EndPoint() + " is established"; textButtonTakeTextFromFile.Visible = true; textButtonTransmitInfo.Visible = true; } else { MessageBox.Show("Enter name or IP-address host", "ERROR"); } } catch (Exception ex) { MessageBox.Show(ex + "\n\n" + ex.Message); } } else { MessageBox.Show("Enter name or IP-address host", "ERROR"); } }