Redirect stream request to another Wowza server

Hi,

We have several Wowza servers in different networks with only one server being able to access the Internet. All clients first connect to the Internet connected server, and a module in this server collects the client information using either IClient.getIp(), HTTPStreamerSessionCupertino.getIpAddress(), HTTPStreamerSessionSmoothStreamer.getIpAddress(), or RTPSession.getIp(), and then redirects the request to the appropriate server depending on the client’s address.

In onAppStart we create a table with networks and their corresponding Wowza server information.

Then, as you can see below, in onConnect and in onHTTPCupertinoStreamingSessionCreate (and in onHTTPSmoothStreamingSessionCreate and onRTPSessionCreate) the redirect takes place:

public void onConnect(IClient client, RequestFunction function, AMFDataList params) {
		for(int i = 0; i < redirect_table.size(); i++)
		{
			try
			{
				if(sameNetwork(redirect_table.get(i).network, client.getIp(), redirect_table.get(i).mask))
				{
					getLogger().info("In same network: " + redirect_table.get(i).network);
					URI query = new URI(client.getUri());
					String redirect = "rtmp://" + redirect_table.get(i).server + ":1935" + query.getPath(); 
					getLogger().info("REDIRECT: " + redirect);
					client.redirectConnection(redirect);
				}
			}
			catch(Exception e)
			{
			
			}
		}
		
	}

Log:

2016-01-15 15:44:00 CST comment server INFO 200 - REDIRECT: rtmp://10.165.90.16:1935/mob-live defaultVHost mob-live definst 22.934

public void onHTTPCupertinoStreamingSessionCreate(HTTPStreamerSessionCupertino httpSession) {
		for(int i = 0; i < redirect_table.size(); i++)
		{
			try
			{
				if(sameNetwork(redirect_table.get(i).network, httpSession.getIpAddress(), redirect_table.get(i).mask))
				{
					getLogger().info("In same network: " + redirect_table.get(i).network);
					URI query = new URI(httpSession.getUri());
					String redirect = "http://" + redirect_table.get(i).server + ":1935/" + query.getPath();
					getLogger().info("REDIRECT: " + redirect);
					httpSession.redirectSession(redirect);
				}
			}
			catch(Exception e)
			{
			
			}
		}
	}

A limitation of our module is that the redirect assumes the application name of the final destination server is the same as the Internet connected server. We’d like, for example, to redirect the client from rtmp://10.165.254.17:1935/mob-live/mob-cam-c001.stream to rtmp://10.165.90.16:1935/mob-internal/mob-cam-c001.stream. We naively tried to just replace the line

String redirect = "rtmp://" + redirect_table.get(i).server + ":1935" + query.getPath(); 

with

String redirect = "rtmp://" + redirect_table.get(i).server + ":1935/mob-internal/mob-cam-c001.stream"; 

to test one stream but it doesn’t work since the stream path apparently is a more complex data structure.

Does anyone have a suggestion on how can we do this?

Thanks!

Please follow up in with our ticket response #155126.

Thanks,

Matt

Thanks for the follow up and for posting the solution.

Regards,

Salvadore

Thanks, Matt.

This simple solution you suggested worked great since we didn’t have to re-generate the whole URI query variable, just replace a substring in the returned string from query.getPath()

String newQueryPath = query.getPath().replace("mob-live","mob-internal");
String redirect = "rtmp://" + redirect_table.get(i).server + ":1935"+newQueryPath;