Connecting Red5 and Amf-php

Its been a long goal for me to connect Red5 to amfphp. You will see frequent needs of interacting with MySQL database from red5. Many people suggest using JDBC. Although thats  valid suggestion, its more of a headache for a non Java developer and the server administrator. Many people also suggest using flash to amfphp direct., but mind it thats the most incorrect way of doing things, when you want it secure.

Here is how you actually get Java to talk to php, the modern style :).  First anf foremost grab a copy of amfphp 1.2 from Sourceforge. Note: download amfphp 1.2,  as amfphp 1.9 is not compatible with red5’s amf decoding.

Step 1.  Setup the amfphp gateway at your server root. Like so:

http://localhost/amfphp

See video on setting up amfphp

Step 2. Download and install red5, then setup a new application using red5plugin in eclipse. (i wont discuss how to setup red5 application here. you can refer to external links for that. Mainly: Red5 developer series videos)

Step 3.  Create a new amfphp service class like this and save as Red5Service.php in services folder of amfphp.

<?php
class Red5Service
{

function  Red5Service()
{
$this->methodTable = array(
"login" => array(
"description" => "login user -> returns true/false",
"access" => "remote",
"arguments" => array ("username","password")
),
"logout" => array(
"description" => "logout user -> returns nothing",
"access" => "remote",
"arguments" => array ("username")
)  
);
}  

function login($username,$password)
{
return true;
}

function logout($username)
{
return;
}
}
?>

Step 4. In your red5 application, connect method  place a call to your amfphp service,  as shown below:

/** {@inheritDoc} */
@Override
public boolean connect(IConnection conn, IScope scope, Object[] params)
{
try
{
RemotingClient client = new RemotingClient("http://localhost/amfphp/gateway.php");
Object[] args = new Object[]{'rajdeep','xyz123'};
Object result = client.invokeMethod("Red5Service.login", args);

if(!result.equals(true)) return false; 
}
catch (IOException e)
{
return false;
}
return true;   
}

As you will see when a user connects to red5 application, the connect handler makes a connection to amfphp gateway and sends the parameters ‘rajdeep’ and ‘xyz123’ as arguments. the amf service can then do its own computations as you want it to and return a boolean expression – true/false at the end. If the java RemotingClient receives a true it lets the connect method accepts the connection else reject it. Also note the try catch block.  also since we dont know what network situations may prevail, so need to be sure that if red5 cannot connect to amfphp it will reject the client connection anyways.

Thats all  for the basics to make things hotter try experimenting with params sent to red5 from flash and the database stuff 🙂

Red5 0.9 out and shining

Red5-0.9-release

The new Red5 0.9 is out. I guess i missed it on release date  🙁 . Nevertheless..  the Red5 team   seems to be doing a wonderful job as they near to the first stable version (1.0) of Red5.  And since its the only good to use and friendly Open source RTMP server out there, its no wonder that everyone have their eye on its progress.  Great job Red5 Team !!

Red5Plugin Overview – Getting Friendly With Red5

From Dominick Accattato’s site , you can see that a good documentation is available as a video on using the Red5 plugin with eclipse for faster and easier Red5 application development. This is great news for all those who ran away just by the thought of setting a Red5 application. The Red5 plugin will get installed into a J2EE version of Eclipse. I personally use Eclipse Galileo. To know more about the plugin and tracking the red5 development, keep up with the Red5 developer’s series on youtube.

  • January 31, 2010
  • Red5

Online Geo Tracker

Tracker is a Red5 application that can track user ip using the RTMP protocol, without using help from php or any other server language. Typically this application demonstrates how red5 knows its incoming connections and can            use this information to authenticate users. The application uses Red5 remoting to query information from Red5.

Click to launch application