private void UdpConfigForm_Load(object sender, EventArgs e) { //判断服务器状态 if (UdpSever.State)//启动状态 { buttonStart.Text = "停止"; textBoxIP.ReadOnly = true; textBoxPort.ReadOnly = true; } else//停止状态 { buttonStart.Text = "启动"; textBoxIP.ReadOnly = false; textBoxPort.ReadOnly = false; } //加载IP和端口 //string str = Ini.Read("网络配置", "IP"); //if (str != "null") //{ // textBoxIP.Text = str; //} //else //{ // textBoxIP.Text = "192.168.2.23"; //} //获取本机IP string name = Dns.GetHostName(); IPAddress[] ipadrlist = Dns.GetHostAddresses(name); foreach (IPAddress ipa in ipadrlist) { if (ipa.AddressFamily == AddressFamily.InterNetwork) { textBoxIP.Text = ipa.ToString(); break; } } string str = Ini.Read("网络配置", "Port"); if (str != "null") { textBoxPort.Text = str; } else { textBoxPort.Text = "18666"; } }
private void MDIParent1_Load(object sender, EventArgs e) { //初始化系统参数 XmlHelper.InitDebug(); int delay = 30; UdpSever.Shell.WriteNotice(delay, "系统消息", "系统启动..."); UdpSever.Shell.WriteNotice(delay, "系统消息", "加载调试信息..."); UdpSever.Shell.WriteNotice(delay, "系统消息", "获取本机IP..."); UdpSever.Shell.WriteNotice(delay, "系统消息", "加载服务器配置..."); UdpSever.Shell.WriteLine(delay, "[服务器][服务器地址][ServerAddress][{0}]", UdpSever.ServerAddress); UdpSever.Shell.WriteLine(delay, "[服务器][设备数][DeviceNum][{0}]", UdpSever.DeviceNum); UdpSever.Shell.WriteLine(delay, "[服务器][寄存器数][RegisterNum][{0}]", UdpSever.RegisterNum); UdpSever.Shell.WriteLine(delay, "[服务器][单帧数据长度][FrameLen][{0}]", UdpSever.FrameLen); UdpSever.Shell.WriteLine(delay, "[服务器][心跳周期][HeartCycle][{0}]秒", UdpSever.HeartCycle); UdpSever.Shell.WriteLine(delay, "[服务器][重发次数][RepeatNum][{0}]", UdpSever.RepeatNum); UdpSever.Shell.WriteLine(delay, "[服务器][超时时间][ResponseTimeout][{0}]", UdpSever.ResponseTimeout); UdpSever.Shell.WriteLine(delay, "[服务器][响应帧缓冲池容量][RESPONSE_MAX_LEN][{0}]", UdpSever.RESPONSE_MAX_LEN); UdpSever.Shell.WriteLine(delay, "[服务器][设备总数][DeviceNum][{0}]\r\n", UdpSever.DeviceNum); #region 获取本机IP,自动开启服务器 string name = Dns.GetHostName(); IPAddress[] ipadrlist = Dns.GetHostAddresses(name); foreach (IPAddress ipa in ipadrlist) { if (ipa.AddressFamily == AddressFamily.InterNetwork) { UdpSever.ipaddress = ipa; UdpSever.Shell.WriteNotice(delay, "系统消息", "本机IP:[{0}]", ipa.ToString()); string str = Ini.Read("网络配置", "Port"); if (str != "null") { UdpSever.port = int.Parse(str); } UdpSever.Shell.WriteNotice(delay, "系统消息", "本机端口:[{0}]", str); } } //自动启动服务器 UdpSever.Resault rs = UdpSever.Start(); //更新界面 udpConfigForm_MyEvent(); #endregion treeView1.Nodes.Clear(); }