Wowza Community

Limit Connections - Filter IPs - Provide Admin Contact

Just wanted tho share the first module I have written for Wowza. It was based off the Connection Limit example by Charlie. I modified it to allow me to also limit by IP addresses as well as provide a contact string that is returned to the player. This is one of my first Java attempts so if you have any tips or improvements please let me know.

Download Compiled Jar

Module Code:

package com.stp.wms.module;
import com.wowza.wms.application.*;
import com.wowza.wms.amf.*;
import com.wowza.wms.client.*;
import com.wowza.wms.module.*;
import com.wowza.wms.request.*;
import com.wowza.wms.logging.*;
public class ModuleConnectionLimit extends ModuleBase {
static final public int MAXCONNECTIONS = 1500;
	
	private int maxApplicationConnections = MAXCONNECTIONS;
	private String ApplicationAdmin = "";
	private String AllowedIPs="";
	private String status="";
	
	public void onAppStart(IApplicationInstance appInstance)
	{
		this.maxApplicationConnections = appInstance.getProperties().getPropertyInt("maxApplicationConnections", maxApplicationConnections);
		this.ApplicationAdmin = appInstance.getProperties().getPropertyStr("ApplicationAdmin", ApplicationAdmin);
		this.AllowedIPs = appInstance.getProperties().getPropertyStr("AllowedIPs", AllowedIPs);
	}
	
	public void onConnect(IClient client, RequestFunction function, AMFDataList params)
	{
		IApplicationInstance appInstance = client.getAppInstance();
		IApplication app = appInstance.getApplication();
		long count = app.getConnectionCounter().getCurrent();
		//Split the list of IPs into an array. Split on , char
		String[] IPList = AllowedIPs.split(",");
		//get IP address of the current user trying to connect
		String userIP = client.getIp();
				
		
		//See if they are allowed in via IP or if admin enabled all IP addresses 
		for(int i=0; i<IPList.length; i++)
		{
			if ((IPList[i].equals("*")) || (userIP.equals(IPList[i])))
			{
				//IP is allowed but is there enough room in the server?
				if ((count+1) > this.maxApplicationConnections)
				{
					//server is full sorry
					client.rejectConnection("Server Full: Limit is: "+this.maxApplicationConnections + " Please Contact: " + this.ApplicationAdmin);
					status = " Connection Denied: IP Allowed but Server Full";
					break;
				}
				else
				{
					//IP is OK and server has room. 
					client.acceptConnection();
					status = " Connection Allowed";
					break;
				}
			}
			
			else 
			{
				//reject connection no IP match ups 
				client.rejectConnection("IP is blocked. Please contact " + this.ApplicationAdmin);
				status = " Connection Denied: IP not Allowed";
			}
		}
		
		
		
		WMSLoggerFactory.getLogger(null).info("Viewer: "+ userIP + " -" + status  + " Current Connections: " + count+1 + " of " + this.maxApplicationConnections);
		
		
	}
	
}

Application.XML Module Code:

                        <Module>
				<Name>ConnectionLimit</Name>
				<Description>Connection Limit</Description>
				<Class>com.stp.wms.module.ModuleConnectionLimit</Class>
			</Module>

Application.XML Properties Code:

                                <Property>
					<Name>maxApplicationConnections</Name>
					<Value>200</Value>
					<Type>Integer</Type>
				</Property>
				<Property>
					<Name>ApplicationAdmin</Name>
					<Value>admin@mydomain.com</Value>
				</Property>
				<Property>
					<Name>AllowedIPs</Name>
					<Value>*</Value>
				</Property>

maxApplicationConnection - The number of connections to allow. Note that if you are doing a live even your Encoder counts as 1.

ApplicationAdmin - This is a string that you can populate with an email address or phone number so people can contact you to let you know that the server is full or their IP is not allowed.

AllowedIPs - List of IP addresses comma ‘,’ separated. If you want everyone to be allowed set it to *.

Feed Back / Comments highly appreciated. I imagine the code can be cleaned up and refined and I will try to post updates here in case anyone finds the module useful.

very good, it is possible to customize the message?

hi Josh Chesarek

Your module is very helpfull. but i have a situation: i have an ip range ex 123.1.1.1-123.1.1.10 needs to add to iplist, so how can i add this list (especialy my ip list is very long).thanks

Hi Josh,

Very good module, I need to limit connections Per IP for protocol http or all.

Can you help me?

regards.