I have the below multicast RTP url.
rtp://[email protected]:5001
How can i parse the below using java
source ip(10.7.220.50)
multicast ip (232.24.0.170)
Port (5001)
CodePudding user response:
The URL "rtp://[email protected]:5001"
fits the model of a hierarchical URI with a server-based authority and no path, query or fragment component. So you should be able to parse it as follows using the standard URI
class:
// Parse ...
URI uri = new URI("rtp://[email protected]:5001");
String protocol = uri.getProtocol(); // "rtp"
String sourceIp = uri.getUserInfo(); // "10.70.220.50"
String multicastIP = uri.getHost(); // "232.24.0.170"
int port = uri.getPort(); // 5001
Note that the sourceIP
won't be checked to ensure it is an IP address.
Refer to the javadoc for java.net.URI
for more details ... including an explanation of the standard terminology I used above.