Best way to create IPEndpoint from string

后端 未结 13 1907
失恋的感觉
失恋的感觉 2020-12-03 06:33

Since IPEndpoint contains a ToString() method that outputs:

10.10.10.10:1010

There should also be

相关标签:
13条回答
  • 2020-12-03 07:23

    It looks like there is already a built in Parse method that handles ip4 and ip6 addresses http://msdn.microsoft.com/en-us/library/system.net.ipaddress.parse%28v=vs.110%29.aspx

    // serverIP can be in ip4 or ip6 format
    string serverIP = "192.168.0.1";
    int port = 8000;
    IPEndPoint remoteEP = new IPEndPoint(IPAddress.Parse(serverIP), port);
    
    0 讨论(0)
提交回复
热议问题