private void StartTCPServer() { if (!commSvc.tcpServerIsRunning) { IPAddress listenIPAddr; if (IPAddress.TryParse(this.txtIPAddr.Text, out listenIPAddr)) { short port = 0; if (short.TryParse(this.txtPort.Text, out port)) { if (commSvc.StartTCPServer(listenIPAddr, port)) { this.btnStartTCPServer.Content = "关闭TCP服务"; this.txtTCPStatus.Text = "TCP服务端已经开启"; this.groupTCPServer.IsEnabled = false; } else { this.txtTCPStatus.Text = "启动TCP服务端失败"; } } else { MessageBox.Show("端口号输入有误!"); } } else { MessageBox.Show("IP地址输入有误!"); } } else { commSvc.StopTCPServer(); this.btnStartTCPServer.Content = "开启TCP服务"; this.txtTCPStatus.Text = "TCP服务端已经关闭"; this.groupTCPServer.IsEnabled = true; } }