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 :)

Popularity: 29% [?]




April 1, 2010  Tags: , ,   Posted in: Java, Php, Red5, RTMP

19 Responses

  1. Thiru - August 10, 2010

    Hi,

    Can U tell me, How to use red5 application for android? can u give me the example to connect amfPhp gateway with android app.

  2. rogger - December 27, 2010

    puede ayudarme como conecto red5 con amfphp para guardar data en mysql y usar geremote para aplicaciones remotas es que estoy asiendo un juego en flash

  3. start - March 10, 2011

    Affordable Web Hosting…

    [...]below you’ll find the link to some sites that we think you should visit[...]…

  4. Anonymous - March 12, 2011

    emini futures…

    [...]below you’ll find the link to some sites that we think you should visit[...]…

  5. הכרויות בטלפון - March 13, 2011

    הכרויות בטלפון…

    [...]the time to read or visit the content or sites we have linked to below the[...]…

  6. portable air conditioning units reviews - March 16, 2011

    portable air conditioner…

    [...]the time to read or visit the content or sites we have linked to below the[...]…

  7. mlm secrets - March 17, 2011

    online mlm secrets…

    [...]the time to read or visit the content or sites we have linked to below the[...]…

  8. Motorcycle Transport - March 19, 2011

    Relocating…

    [...]plenty of time to read through or perhaps go to written content or internet sites we have now linked to[...]…

  9. Car Warranty - March 22, 2011

    Auto Warranty…

    [...]below you’ll find the link to some sites that we think you should visit[...]…

  10. cash in gold - March 23, 2011

    Get Cash For Gold…

    [...]below you’ll find the link to some great sites that we believe you should visit[...]…

  11. order viagra - March 26, 2011

    Alloha)…

    [...]Greetings everyone, This webpage is terrific and so is how the matter was expanded. I like some of the comments as well although I would prefer we all maintain it on topic in order add value to the subject[...]…

  12. fastcashloant - March 30, 2011

    hi everyone

  13. Property Solicitors - March 30, 2011

    Conveyancing Solicitors…

    [...]below you’ll find the link to some sites that we think you should visit[...]…

  14. generic viagra - March 31, 2011

    Alloha)…

    [...]Greetings everyone, This webpage is terrific and so is how the matter was expanded. I like some of the comments as well although I would prefer we all maintain it on topic in order add value to the subject[...]…

  15. effective cellulite reduction - April 3, 2011

    Fantastic Website…

    [...]below you’ll find the link to some sites that we think you should visit[...]…

  16. plastic surgery recovery - April 4, 2011

    Infertility los angeles…

    [...]the time to read or visit the content or sites we have linked to below the[...]…

  17. topamax lawsuits - April 6, 2011

    candle supplies…

    [...]below you’ll find the link to some sites that we think you should visit[...]…

  18. Dremel Stylus - April 6, 2011

    Dremel Stylus…

    Bookmarked your site, so I can visit frequently, thank you!…

  19. Hunstanton - April 6, 2011

    Hunstanton…

    Trackback, I have linked to your site, thank you!…

Leave a Reply