Remoting a facility by which a client can call a server method in a request response fashion. Unlike RTMP remoting services are performed using AMF over HTTP/HTTPS. Red5 can act as both a RTMP server as well as a HTTP/HTTPS remoting server. Remoting enables non rtmp clients to access Red5 methods. A very practical approach would be to request chat room user count for example. Using remoting you can request such data without consuming too much server resources as in a RTMP connection. You can also create chat programs with simple amf-polling as well. Remoting also lets you sync data types over both ends (client-server)
In this article we will see how to consume services on Red5 using remoting. You may want to refer red5.org about a few important things.
Creating a basic service class:
Though i wont be explaining how to create a Red5 application here, and i assume you already know that before starting off with remoting , still we will see the basic of setting it all up, as it includes creating a basic application as well.
Step 1: – Launch Eclipse
Note: Use only J2EE version of eclipse when working in Red5 with Red5 plugin for best results.
Step 2: – Create a basic Red5 application called “remotingdemo“.
(you can follow the Red5 developer series by Dominick Accattato on youtube to get started with Red5 basics)
Step 3: – Create a service class. This class will hold our methods for remoting. Red5 maintain tight security by not allowing the client to call just any method on the server. You must register the class as service handler before you expose it to client. So here for our example we create a class called RemoteMethods and this class will implement the IServiceHandlerProvider interface found at org.red5.server.api.service.IServiceHandlerProvider.
Step 4: – Register this class as a service handler. Now that we have create our class that will hold service methods, we need to expose it to our client. Red5 allows us to do this in 2 ways.
- Expose the class as a service handler by defining it as a Bean in the red5-web.xml
- Expose the class as a service handler by registering it in the application code itself.
For our purpose we will be looking at the second way of exposing services. However in the end i will show you how we use the first method as well. To understand handlers better you can refer to red5.org here.
So to register this class as a service handler, we will implement the appStart() method in our Red5 application and register it there.
public boolean appStart(IScope app)
Object handler = new org.red5.core.RemoteMethods();
Note: When using registerServiceHandler, you may need the spring-core-2.5.6.jar file from red5 lib directory.
So as you see in the snippet above , that’s what out appStart will look like finally. We have registered the class that we created – “RemoteMethods” in the root scope of our application and it will be referenced as “RemoteClass“. This hides the actual class name.