// 检查PORT是否被占用,提示用户 private void btnCheck_Click(object sender, EventArgs e) { if (!isPortSet) { SystemSounds.Exclamation.Play(); MessageBox.Show(this, "Monitor port was not specified.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // 显示加载中窗体 ProgressSpecifier ps = new ProgressSpecifier(); ps.Show(); bool rep = isTCPPortInUse(Int32.Parse(this.txtPort.Text)); ps.Close(); if (rep == false) { MessageBox.Show(this, "This port is not in use at this time.", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show(this, "This port is occupied at this time. Please change one.", "Info", MessageBoxButtons.OK, MessageBoxIcon.Warning); } }
// 测试连通性 private void btnPing_Click(object sender, EventArgs e) { if (!txtAddrHasText) { SystemSounds.Exclamation.Play(); MessageBox.Show(this, "Target address was not specified.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } // 显示加载中窗体 ProgressSpecifier ps = new ProgressSpecifier(); ps.Show(); // 尝试ping Ping ping = new Ping(); byte[] sendBuf = Encoding.UTF8.GetBytes("Ping test"); int timeout = 500; PingReply rep = ping.Send(txtAddr.Text, timeout, sendBuf); ps.Close(); if (rep.Status == IPStatus.Success) { MessageBox.Show(this, "Target is connectable.\nRemote Server: " + rep.Address + "\nRoundtrip Time: " + rep.RoundtripTime + " ms", "Ping Info", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show(this, "Target is not connectable.\nRemote Server: " + rep.Address + "\nTimeout Occurred.", "Ping Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }