public static bool TryParseFromUri(Uri uri, out UdpPortConfig opt) { if (!"udp".Equals(uri.Scheme, StringComparison.InvariantCultureIgnoreCase)) { opt = null; return(false); } var coll = HttpUtility.ParseQueryString(uri.Query); opt = new UdpPortConfig { LocalHost = IPAddress.Parse(uri.Host).ToString(), LocalPort = uri.Port, }; var rhost = coll["rhost"]; if (rhost != null) { opt.RemoteHost = IPAddress.Parse(rhost).ToString(); } var rport = coll["rport"]; if (rport != null) { opt.RemotePort = int.Parse(rport); } return(true); }
public UdpPort(UdpPortConfig config) { _recvEndPoint = new IPEndPoint(IPAddress.Parse(config.LocalHost), config.LocalPort); if (!config.RemoteHost.IsNullOrWhiteSpace() && config.RemotePort != 0) { _sendEndPoint = new IPEndPoint(IPAddress.Parse(config.RemoteHost), config.RemotePort); } }
public static IPort Create(string connectionString) { var uri = new Uri(connectionString); UdpPortConfig udp; if (UdpPortConfig.TryParseFromUri(uri, out udp)) { return(new UdpPort(udp)); } SerialPortConfig ser; if (SerialPortConfig.TryParseFromUri(uri, out ser)) { return(new CustomSerialPort(ser)); } throw new Exception(string.Format(RS.RemoteStreamFactory_CreateStream_Connection_string_is_invalid, connectionString)); }