public bool ParseEndpoint(string src, out PeerProtocol protocol, out IPAddress ipAddress, out int port) { if (src.Contains(":")) { var temp = src.Split(':'); Throw.If(temp.Length != 2, "Invalid endpoint format"); src = temp[0]; port = int.Parse(temp[1]); } else { port = this.Port; } if (!IPAddress.TryParse(src, out ipAddress)) { //if (Socket.OSSupportsIPv6) //{ // if (src == "localhost") // { // ipAddress = IPAddress.IPv6Loopback; // } // else // { // ipAddress = Endpoint.ResolveAddress(src, AddressFamily.InterNetworkV6); // } //} if (ipAddress == null) { ipAddress = Endpoint.ResolveAddress(src, AddressFamily.InterNetwork); } } if (ipAddress == null) { throw new Exception("Invalid address: " + src); } else { src = ipAddress.ToString(); } protocol = PeerProtocol.TCP; return(true); }
public Endpoint(PeerProtocol protocol, string host, int port) { this.Protocol = protocol; this.Host = host; this.Port = port; }