NetworkHelper.cs 575 B

12345678910111213141516171819202122
  1. using System.Net;
  2. namespace KYFramework
  3. {
  4. public static class NetworkHelper
  5. {
  6. public static IPEndPoint ToIPEndPoint(string host, int port)
  7. {
  8. return new IPEndPoint(IPAddress.Parse(host), port);
  9. }
  10. public static IPEndPoint ToIPEndPoint(string address)
  11. {
  12. int index = address.LastIndexOf(':');
  13. string host = address.Substring(0, index);
  14. string p = address.Substring(index + 1);
  15. int port = int.Parse(p);
  16. return ToIPEndPoint(host, port);
  17. }
  18. }
  19. }