Code:
package com.wowza.wms.plugin.collection.module;
import com.wowza.wms.amf.*;
import com.wowza.wms.application.*;
import com.wowza.wms.client.*;
import com.wowza.wms.httpstreamer.model.IHTTPStreamerSession;
import com.wowza.wms.request.*;
import com.wowza.wms.rtp.model.*;
import com.wowza.wms.module.*;
public class ModuleLimitConnectionsToApplication extends ModuleBase
{
static final public int MAXCONNECTIONS = 200;
private int maxApplicationConnections = MAXCONNECTIONS;
public void onAppStart(IApplicationInstance appInstance)
{
this.maxApplicationConnections = appInstance.getProperties().getPropertyInt("maxApplicationConnections", maxApplicationConnections);
getLogger().info("ModuleLimitConnectionsToApplication limit: " + maxApplicationConnections);
}
public void changeLimit(IClient client, RequestFunction function,
AMFDataList params) {
client.getAppInstance().broadcastMsg("handlerName");
Integer newLimit = params.getInt(PARAM1);
this.maxApplicationConnections = newLimit;
}
public void onConnect(IClient client, RequestFunction function, AMFDataList params)
{
IApplicationInstance appInstance = client.getAppInstance();
IApplication app = appInstance.getApplication();
long count = app.getConnectionCounter().getCurrent();
String flashver = client.getFlashVer();
getLogger().info("Flashver: " + flashver);
Boolean isPublisher = false;
try
{
isPublisher = flashver.startsWith(client.getAppInstance().getProperties().getPropertyStr("AllowEncoder"));
}
catch(Exception ex)
{
}
getLogger().info("ModuleLimitConnectionsToApplication count: " + (count + 1));
if ((count+1) > this.maxApplicationConnections && !isPublisher)
{
client.rejectConnection("Over application connection limit ["+app.getName()+"/"+appInstance.getName()+"]: Limit is: "+this.maxApplicationConnections);
getLogger().info("ModuleLimitConnectionsToApplication Flash connection rejected ");
}
}
public void onHTTPSessionCreate(IHTTPStreamerSession httpSession)
{
IApplicationInstance appInstance = httpSession.getAppInstance();
IApplication app = appInstance.getApplication();
long count = app.getConnectionCounter().getCurrent();
getLogger().info("ModuleLimitConnectionsToApplication count: " + (count + 1));
if ((count+1) > this.maxApplicationConnections)
{
httpSession.rejectSession();
getLogger().info("ModuleLimitConnectionsToApplication Smooth connection rejected ");
}
}
public void onRTPSessionCreate(RTPSession rtpSession)
{
IApplicationInstance appInstance = rtpSession.getAppInstance();
IApplication app = appInstance.getApplication();
long count = app.getConnectionCounter().getCurrent();
getLogger().info("ModuleLimitConnectionsToApplication count: " + (count + 1));
if ((count+1) > this.maxApplicationConnections)
{
rtpSession.rejectSession();
getLogger().info("ModuleLimitConnectionsToApplication RTSP connection rejected ");
}
}
}
Add this Module last in the Modules list of /conf/[app-name]/Application.xml
Code:
<Module> <Name>ModuleLimitStreamViewers</Name> <Description>Limit connects to an Application</Description> <Class>com.wowza.wms.plugin.collection.module.ModuleLimitConnectionsToApplication</Class> </Module>
Code:
<Property> <Name>maxApplicationConnections</Name> <Value>200</Value> <Type>Integer</Type> </Property>
The logs will show the limit and the number of connections. In this example, it is limited to 200 connections.
Code:
comment server INFO 200 - ModuleLimitConnectionsToApplication limit: 200
Code:
comment server INFO 200 - ModuleLimitConnectionsToApplication count: 01
Code:
comment server INFO 200 - ModuleLimitConnectionsToApplication Flash connection rejected comment server INFO 200 - ModuleLimitConnectionsToApplication Cupertino connection rejected comment server WARN 200 - HTTPStreamerAdapterCupertinoStreamer.onPlaylist[vod/mp4:sample.mp4/playlist.m3u8]: Over license limit comment server WARN 200 - HTTPStreamerAdapterSanJoseStreamer.onPlaylist: Over license limit
If you are using a Telestream Wirecast encoder, set the value to "Wirecast". If you are using an RTMP live encoder that uses the Flash Media version, set this value to "FM".
<Property>
<Name>AllowEncoder</Name>
<Value>Wirecast</Value> <!--FM, Wirecast-->
</Property>
- Click here, if you are having problems or would like to discuss this article.
- Leave a comment below, if there is some aspect of this article you would like to see changed or improved.


Article List
Categories
Wowza Media