# Redirect stream request to another Wowza server

**URL:** <https://community.wowza.com/t/redirect-stream-request-to-another-wowza-server/46473>\
**Category:** Wowza Developer Dojo\
**Tags:** wowza-streaming-server-java-api\
**Created:** [January 18, 2016, 9:15am UTC](https://community.wowza.com/t/redirect-stream-request-to-another-wowza-server/46473 "2016-01-18T09:15:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lu\_Al](https://avatars.discourse-cdn.com/v4/letter/l/f17d59/32.png) [@Lu\_Al](https://community.wowza.com/u/Lu_Al)\
**Post date:** [January 18, 2016, 9:15am UTC](https://community.wowza.com/t/redirect-stream-request-to-another-wowza-server/46473/1 "2016-01-18T09:15:47Z")

</div>

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:

```auto
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

```auto
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

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

```

with

```auto
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!

---

<div class="post-metadata">

**Author:** ![Matt\_Young](https://sea2.discourse-cdn.com/flex002/user_avatar/community.wowza.com/matt_young/32/389_2.png) [@Matt\_Young](https://community.wowza.com/u/Matt_Young)\
**Post date:** [January 20, 2016, 8:39am UTC](https://community.wowza.com/t/redirect-stream-request-to-another-wowza-server/46473/2 "2016-01-20T08:39:30Z")

</div>

Please follow up in with our ticket response #155126.

Thanks,

Matt

---

<div class="post-metadata">

**Author:** ![sal\_jefferson](https://avatars.discourse-cdn.com/v4/letter/s/6de8d8/32.png) [@sal\_jefferson](https://community.wowza.com/u/sal_jefferson)\
**Post date:** [January 28, 2016, 8:06am UTC](https://community.wowza.com/t/redirect-stream-request-to-another-wowza-server/46473/3 "2016-01-28T08:06:09Z")

</div>

Thanks for the follow up and for posting the solution.

Regards,

Salvadore

---

<div class="post-metadata">

**Author:** ![Lu\_Al](https://avatars.discourse-cdn.com/v4/letter/l/f17d59/32.png) [@Lu\_Al](https://community.wowza.com/u/Lu_Al)\
**Post date:** [January 22, 2016, 2:21pm UTC](https://community.wowza.com/t/redirect-stream-request-to-another-wowza-server/46473/4 "2016-01-22T14:21:09Z")

</div>

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()

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

```
