private void cmdStop_Click(object sender, EventArgs e) { AsyServer.Stop(); lb.Items.Add("Server Gestopt"); cmdStart.Enabled = true; cmdStop.Enabled = false; }
private void btnStart_Click(object sender, EventArgs e) { if (Properties.Settings.Default.IP != txtIP.Text || Properties.Settings.Default.Port != Convert.ToInt32(txtPort.Text)) { var dialogresult = MessageBox.Show("You haven't save your settings!\nDo you want to discard the changes?", "Discard", MessageBoxButtons.YesNo, MessageBoxIcon.Information); if (dialogresult == DialogResult.No) { return; } else { txtIP.Text = Properties.Settings.Default.IP; txtPort.Text = Properties.Settings.Default.Port.ToString(); } } if (btnStart.Text == "Start") { IPAddress address = IPAddress.Parse(txtIP.Text); server = new AsyncTcpServer(address, Convert.ToInt32(txtPort.Text)); server.PacketReceived += Server_PacketReceived; server.ClientConnected += Server_ClientConnected; server.ClientDisconnected += Server_ClientDisconnected; try { server.Start(); btnStart.Text = "Stop"; lblSate.Text = "online"; lblSate.ForeColor = Color.Green; txtIP.Enabled = false; txtPort.Enabled = false; btnSave.Enabled = false; } catch (Exception ex) //Todo: Spezifische Exeption abrufen { MessageBox.Show("Server start failed", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else if (btnStart.Text == "Stop") { try { server.Stop(); btnStart.Text = "Start"; lblSate.Text = "offline"; lblSate.ForeColor = Color.Red; txtIP.Enabled = true; txtPort.Enabled = true; btnSave.Enabled = true; } catch (Exception ex) //Todo: Spezifische Exeption abrufen { MessageBox.Show("Server stop failed", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
public static void Stoppen(Label lblstatus) { try { server.Stop(); lblstatus.Text = "Server ist aus."; lblstatus.ForeColor = Color.Red; } catch (Exception) { MessageBox.Show("Fehler beim stoppen vom Server.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }