/// <summary>
/// 服务端口的监控
/// </summary>
public class ServerPortCTR
{
// The port number for the remote远程 device.
private const int port = 8989;
// ManualResetEvent instances signal completion.
private static ManualResetEvent connectDone = new ManualResetEvent(false);//通知一个或多个正在等待的线程已发生事件。无法继承此类。
private static ManualResetEvent sendDone = new ManualResetEvent(false);
private static ManualResetEvent receiveDone = new ManualResetEvent(false);
// The response from the remote device.
private static String response = String.Empty;
/// <summary>
/// 服务器端口响应时间,-1表示有异常
/// </summary>
/// <param name="IP">IP地址</param>
/// <param name="port">端口号</param>
/// <returns>响应时间</returns>
public static int StartClient(string IP,int port)//启动客户端
{
// Connect to a remote device.
try
{
IPAddress ipAddress = IPAddress.Parse(IP);//Ip地址
IPEndPoint remoteEP = new IPEndPoint(ipAddress, port);//将网络终点表示为IP地址和端口
// Create a TCP/IP socket.
Socket client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, Protoc
服务器端口的监控(得到其响应时间)
最新推荐文章于 2024-11-01 14:42:21 发布