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); } } }
private void cmdStart_Click(object sender, EventArgs e) { //AsyServer = new AsyncTcpServer(IPAddress.Parse("10.200.14.187"), 1234); AsyServer = new AsyncTcpServer(IPAddress.Any, 1234); AsyServer.Start(); AsyServer.ClientConnected += Server_ClientConnected; AsyServer.ClientDisconnected += Server_ClientDisconnected; AsyServer.PacketReceived += Server_PacketReceived; lb.Items.Add("Server Gestartet"); cmdStart.Enabled = false; cmdStop.Enabled = true; }
public static void Starten(TextBox txtip, TextBox txtport, Label lblstatus, Label lblclients) { lblClients = lblclients; IPAddress address = IPAddress.Parse(txtip.Text); server = new AsyncTcpServer(address, Convert.ToInt16(txtport.Text)); server.ClientConnected += Server_ClientConnected; server.ClientDisconnected += Server_ClientDisconnected; try { server.Start(); lblstatus.Text = "Server gestartet"; lblstatus.ForeColor = Color.Green; } catch (Exception) { MessageBox.Show("Fehler beim starten vom Server.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }