Bind exception

June 25th, 2008

I've seen a few posts on the Red5 list where users encountered the "bind" exception when starting Red5; I just had it happen on my PC. Usually its a service running on your machine taking up port 80 (HTTP), port 443 (HTTPS), or 1935 (RTMP). This normally means that IIS, Apache, FMS, or Red5 are running and already bound to these ports; 99% of the time I don't see this issue because of the tight lock I keep on my running services. Today I got the exception and I traced it to Pidgin (an IM client like Trillian that does "them" all), the odd thing is that it was using port 1935 (RTMP). If you get the bind issue, check your running processes and kill-off or reconfigure them as needed. Using the following commands will show your bound ports:
in windows
netstat -an
in linux
netstat -pan
The linux command will give additional details such as the application/service name. For windows you can use TcpView or some similar application to determine the application holding the port.

Bootstraping Red5

June 12th, 2008

Even being part of the Red5 development team, I always found adding or changing libraries a pain. To alleviate this I created a Bootstrap class. Its purpose is to look in the red5/lib directory and grab urls for all the jars contained therein and add them to a classpath. I have also added logic to keep only the most recent versions of libraries, although this logic could use some work and is not perfect. The code will miss libraries with slight name changes such as: jcl104-over-slf4j-1.5.0.jar vs. jcl-over-slf4j-1.5.2.jar.

Red5 previously had two ways to start up: standalone and war. The standalone method uses the classpath embedded in the /META-INF/manifest.mf located in the red5.jar; if your library was not listed here your application would not work, unless you placed it within your applications classpath. Your application classpath would consist of any class residing in your /WEB-INF/classes directory or in a jar located in your /WEB-INF/lib directory.

The bootstrap method of start up should also allow you to share libraries amongst your applications, I have found problems with some libraries like Hibernate but most issues seem to be resolved by updating Spring to 2.5. If you have problems you can always move the jar to your applications lib directory. So without further ado, here is how you launch Red5 using the bootstrap class:

java -Djava.security.manager -Djava.security.policy=conf/red5.policy
-cp red5.jar org.red5.server.Bootstrap

Note: The Bootstrap class is only available in version 0.7.1 and later

Red5 Eclipse plugin

May 31st, 2008

Being part of the Red5 team for so long, I have seen a lot of people request that the application creation process be made simpler. We have talked internally about creating an Eclipse plugin for quite some time and we were certainly inspired by Wowza's plugin ;) So without further rambling I send you to Dominick to see his latest plugin via screencast and maybe if you ask nicely he'll let you in the beta!

Apache and RTMPT

May 27th, 2008

Some of you may find yourself in a situation where your Red5 server is on an internal network or otherwise un-reachable from the Internet. This set of rewrite rules will allow you to provide access to Red5 using an Apache web server (assuming the web server has access to the Internet).
The following rules assume that your Red5 server is running on a server with the IP address of 10.0.0.5, accepting HTTP connections on port 5080, and your application name is "myapp".

    RewriteRule ^/(open/.*)$ http://10.0.0.5:5080/myapp/$1 [P]
    RewriteRule ^/(send/.*)$ http://10.0.0.5:5080/myapp/$1 [P]
    RewriteRule ^/(idle/.*)$ http://10.0.0.5:5080/myapp/$1 [P]
    RewriteRule ^/(close/.*)$ http://10.0.0.5:5080/myapp/$1 [P]

If you need more information on mod_rewrite, use this link.

Using JMX in Red5

May 27th, 2008

The first step to perform when using JMX in Red5 is to get the MBeanServer. Once you have a server instance you may look up, create, register, and unregister mbeans. MBeans provide access to methods on classes which implement the associated MBean interface, most of the details about this are beyond the scope of this post. Today, we will cover the loading and unloading of a Red5 context.

 
    MBeanServer mbs = JMXFactory.getMBeanServer();
    ObjectName oName = JMXFactory.createObjectName("type", "ContextLoader");
    ContextLoaderMBean contextLoader = null;
    if (mbs.isRegistered(oName)) {
        contextLoader = (ContextLoaderMBean) MBeanServerInvocationHandler.newProxyInstance
(mbs, oName, ContextLoaderMBean.class, true);
        System.out.println("Context loader was found");
    } else {
        System.err.println("Context loader was not found");
    }
 

Once you have the context loader you can load the context. The context in this case is a Red5 default context consisting of a group of web applications that have been Red5 enabled. To be Red5 enabled means that they have the proper configurations and a class extending org.red5.server.adapter.ApplicationAdapter.

 
    if (contextLoader != null) {
	contextLoader.loadContext("localhost", "c:/red5/webapps/red5-default.xml");
    }
 

To unload the context perform this step.

 
    if (contextLoader != null) {
	contextLoader.unloadContext("localhost");
    }
 

See how simple that is?

Please note that I do not condone the use of System.out as a substitute for proper logging

RTMPS in Red5

May 26th, 2008

Red5 now supports RTMPS, many of you will be very happy about this new feature. Previously, users had to use stunnel or some other "hack" to implement this feature that FMS supports. RTMPS was easy to implement after I realized RTMPS is RTMPT over SSL; this is a big revelation, since I started out thinking it was RTMP via SSL/TLS. So without further rambling, here is how to setup RTMPS in Red5 at zero cost. I would rate the procedure below as Intermediate level.

Create a self-signed certificate

There are many articles on the web which describe how to complete this first task, but I will explain how to do this with the tool included with Java. Execute this command from your console:

keytool -genkey -alias red5 -keyalg RSA -keysize 512 -validity 3650 \
    -keystore keystore -keypass password -storepass password \
    -dname "CN=localhost,OU=Red5,O=Red5,L=Henderson,ST=NV,C=US"

You may change a few of these options if you prefer, but I suggest that you only change some of the DName fields: Location (L), State (ST), and Country (C). Otherwise the feature may not work. Also note that if you are going to use RTMPS on the Internet, you will probably want to get a CA signed certificate.

Upon completion of this task you will have a file named "keystore", keep track of this since you will need it later on.

Get Red5

The RTMPS feature is not released as part of the current stable server (version 0.7.0) it is however available via SVN starting with revision 2819. This means you have to get an Subversion client, grab the source, build, and deploy; I will not be covering all these steps in this post. Go to http://osflash.org/red5 for links and information on Red5.

Configuration

Once you have Red5, copy the keystore file you created with step one into your conf directory (overwrite the current keystore file in the directory if prompted). The configuration file containing the parameter for RTMPS is in conf/red5-core.xml and you will need to update the RTMPS section if you changed the keystore password. The other configuration file to make note of is red5.properties, it contains the port assignments for the supported protocols. Make sure that you have your ports configured correctly; Adobe suggests that RTMPS be defaulted to port 443, normally this port is reserved for HTTPS. If you change this port to something other than 443 you will need to update your NetConnection urls with the correct port.

For Advanced users, there are a few other options you may specify on your RTMPS connection such as the supported ciphers. You can find additional information on this here. The connectioProperties section is where you would place these additional key / value pairs.

Engage

Start the server and test your applications. I personally tested with the oflaDemo that comes bundled in Red5. Go to http://localhost:5080/demos/oflaDemo.swf and change the rtmp url to rtmps://localhost/oflaDemo et voila! This of course assumes that you didnt change any ports.

Debugging

To see what is going on with SSL at a really low level you can enable this option in your startup:

 -Djavax.net.debug=ssl

It will cause additional information to be displayed on the console.