/// <summary> /// UDP服务 /// </summary> private void btnUDP_Click(object sender, EventArgs e) { btnUDP.Enabled = false; if (UdpServer == null) { UdpServer = new AsyncUDPServer(); } if (!UdpServer.IsStartListening) { UdpServer.Start(); txtMsg.AppendText(DateTime.Now + Environment.NewLine + "UDP服务器启动" + Environment.NewLine); lblUDP.Text = "UDP服务器地址:" + HelpCommonLib.NetworkAddress.GetIPAddress() + ":" + UdpServer.ListenProt; PicBoxUDP.BackgroundImage = Properties.Resources._07822_48x48x8BPP_; btnUDP.Text = "UDP停止服务"; btnUDP.Enabled = true; } else { txtMsg.AppendText(DateTime.Now + Environment.NewLine + "UDP服务器停止" + Environment.NewLine); UdpServer.Close(); PicBoxUDP.BackgroundImage = Properties.Resources._07821_48x48x8BPP_; btnUDP.Text = "UDP端口错误"; } }
/// <summary> /// UDP服务 /// </summary> private void btnUDP_Click(object sender, EventArgs e) { btnUDP.Enabled = false; if (UdpServer == null) { UdpServer = new AsyncUDPServer(); } // AsyncUDPServer UdpServer2 = new AsyncUDPServer(6001); //UdpServer2.Start(ref m_np); if (!UdpServer.IsStartListening) { // UdpServer.Start(); UdpServer.Start(ref m_np); //// 尝试自动开始串口信息处理 //PortSettings setting = AddPortForm.AutoPortSetting; //if (setting != null) //{ // // 添加新的设备页 // controlPage = new AisControl(setting,UdpServer); // if (controlPage.IsOpen()) // { // controlPage.Dock = DockStyle.Fill; // TabPage page = new TabPage(setting.PortName); // tabPageEx6.Controls.Add(controlPage); // } //} // lblUDP.Text = "UDP服务器地址:" + HelpCommonLib.NetworkAddress.GetIPAddress() + ":" + UdpServer.ListenProt; string str = "地址:" + HelpCommonLib.NetworkAddress.GetIPAddress() + ":" + UdpServer.ListenProt; txtMsg.AppendText(DateTime.Now + Environment.NewLine + "UDP服务器启动 " + str + Environment.NewLine); //str = "地址:" + HelpCommonLib.NetworkAddress.GetIPAddress() + ":" + UdpServer2.ListenProt; //txtMsg.AppendText(DateTime.Now + Environment.NewLine + "UDP服务器启动 " + str + Environment.NewLine); // lblUDP.Text = "UDP服务器地址:" + HelpCommonLib.NetworkAddress.GetIPAddress() + ":" + UdpServer2.ListenProt; PicBoxUDP.BackgroundImage = Properties.Resources._07822_48x48x8BPP_; btnUDP.Text = "UDP停止服务"; btnUDP.Enabled = true; //timer1.Start(); } else { txtMsg.AppendText(DateTime.Now + Environment.NewLine + "UDP服务器停止" + Environment.NewLine); UdpServer.Close(); PicBoxUDP.BackgroundImage = Properties.Resources._07821_48x48x8BPP_; btnUDP.Text = "UDP端口错误"; // UdpServer2.Close(); } }