public void TryParseIPEndPoint() { Assert.True(NetHelpers.TryParseIPEndPoint("127.0.0.1:1337", out var parsedIp)); Assert.Equal(new IPEndPoint(IPAddress.Loopback, 1337), parsedIp); Assert.True(NetHelpers.TryParseIPEndPoint("[::1]:1337", out var parsedIpv6)); Assert.Equal(new IPEndPoint(IPAddress.IPv6Loopback, 1337), parsedIpv6); }
/// <summary> /// Creates a Socket server given an IP endpoint. /// </summary> /// <param name="address">The IP address and port of the server, as a string.</param> /// <param name="serverRecord">A new <see cref="ServerRecord"/>, if the address was able to be parsed. <c>null</c> otherwise.</param> /// <returns><c>true</c> if the address was able to be parsed, <c>false</c> otherwise.</returns> public static bool TryCreateSocketServer(string address, [NotNullWhen(true)] out ServerRecord?serverRecord) { if (!NetHelpers.TryParseIPEndPoint(address, out var endPoint)) { serverRecord = default(ServerRecord); return(false); } serverRecord = new ServerRecord(endPoint, ProtocolTypes.Tcp | ProtocolTypes.Udp); return(true); }