NetworkHelper.cs 468 B

123456789101112131415161718192021
  1. using System.Net;
  2. namespace WS
  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. }