How can I test a connection to a server with C# given the server's IP address?

前端 未结 4 1375
野的像风
野的像风 2020-12-30 04:15

How can I programmatically determine if I have access to a server with a given IP address using C#?

4条回答
  •  遥遥无期
    2020-12-30 04:50

    This should do it

    bool ssl;
    ssl = false;
    int maxWaitMillisec;
    maxWaitMillisec = 20000;
    int port = 555;
    
    success = socket.Connect("Your ip address",port,ssl,maxWaitMillisec);
    
    
    if (success != true) {
    
        MessageBox.Show(socket.LastErrorText);
        return;
    }
    

提交回复
热议问题