public static RtpListener Open(string uri) { var test = new Regex(@"(?<proto>[a-zA-Z]+)://(?<ip>[\d\.]+)?@(?<joinip>[\d\.]+)?(:(?<port>\d+))?"); int port; IPAddress ip; IPAddress joinip; Assert.That(test.IsMatch(uri), () => new ArgumentException("Please use a format of 'udp://@MCIP:PORT' where MCIP is a valid multicast IP address.", "uri")); var m = test.Match(uri); Assert.AreEqual(m.Groups["proto"].Value.ToLower(), "udp", "protocol"); if (!IPAddress.TryParse(m.Groups["ip"].Value, out ip)) { ip = IPAddress.Any; } if (!IPAddress.TryParse(m.Groups["joinip"].Value, out joinip)) { joinip = IPAddress.Any; } if (!int.TryParse(m.Groups["port"].Value, out port)) { port = 1234; } var client = new RtpListener(new IPEndPoint(ip, port)); client.StartListening(); //check if its MC if ((joinip.GetAddressBytes()[0] & 224) == 224) { client._listener.JoinMulticastGroup(joinip); } return(client); }
public static RtpListener Open(string uri) { var test = new Regex(@"(?<proto>[a-zA-Z]+)://(?<ip>[\d\.]+)?@(?<joinip>[\d\.]+)?(:(?<port>\d+))?"); int port; IPAddress ip; IPAddress joinip; Assert.That(test.IsMatch(uri), () => new ArgumentException("Please use a format of 'udp://@MCIP:PORT' where MCIP is a valid multicast IP address.", "uri")); var m = test.Match(uri); Assert.AreEqual(m.Groups["proto"].Value.ToLower(), "udp", "protocol"); if (!IPAddress.TryParse(m.Groups["ip"].Value, out ip)) ip = IPAddress.Any; if (!IPAddress.TryParse(m.Groups["joinip"].Value, out joinip)) joinip = IPAddress.Any; if (!int.TryParse(m.Groups["port"].Value, out port)) port = 1234; var client = new RtpListener(new IPEndPoint(ip, port)); client.StartListening(); //check if its MC if((joinip.GetAddressBytes()[0] & 224) == 224) client._listener.JoinMulticastGroup(joinip); return client; }