can someone please suggest way to communicate between Air(Action script) App and node.js server?
e.g.
Communication between PHP and Flash(Action Script) application using AMFPHP
BlazeDS for Java+Adobe Flex and Adobe Integrated Runtime (AIR)
Please send me your suggestions, any tutorial, or PoC sample code
Thanks in Advance.
Here is a sample I wrote for a blog. I think the code itself pretty much explains itself.
var urlString:String = "http://localhost:1337/";
function Submit():void
{
var requestVars:URLVariables = new URLVariables();
requestVars.Username = "guest";
var request:URLRequest = new URLRequest();
request.url = urlString;
request.method = URLRequestMethod.GET;
request.data = requestVars;
var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.TEXT;
loader.addEventListener(Event.COMPLETE, loaderCompleteHandler);
try { loader.load(request); }
catch (error:Error) { // Handle Immediate Errors }
}
function loaderCompleteHandler(e:Event):void
{
trace(e.target.data); // Response Text
}
Brief about the code snippet:
URL is set to Localhost port 1337 where the nodeJS would be hosted.
The variable set is a test field UserName which is checked for in the server script.
Server Side NodeJS Code :
var http = require('http'), url = require('url');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
var urlObj = url.parse(req.url, true);
if(urlObj.query["Username"] == "guest") res.end("True");
else res.end("False");
}).listen(1337, "127.0.0.1");
console.log('Server running at http://127.0.0.1:1337/');
Brief about the code snippet: