Flex Whois Tutorial
Overview
The aim of this tutorial is to create a simple whois lookup application using the Flex 2 SDK and the AMFPHP gateway.
What you will need
Webserver that supports PHP (I used Apache2 in this tutorial)
PHP 5.1.6 (other versions should also work)
- Experience in at least one programming language will help, such as javascript.
How it works
Once written your Flex application will communicate with a PHP service using the Action Message Format (AMF), a binary message format designed for the ActionScript object model.
Using AMF and PHP we can expose functionality on the server making use of the many classes and libraries available to PHP (or any other language for that matter).
Flex Application (*.SWF)
Let's start with the client as this will introduce you to the power of Flex and also provide you with an interface (it's always nice to see something as you develop). |
The Flex Whois Application
Ok so lets get to work on the Whois client. Creating a Flex application is as simple as editing an XML document so fire up your favourite editor, paste in the XML document found Here and save it as flexwhois.mxml.
So what is this MXML file? Well basically this file contains the code that describes the user interface and how to layout the components. It also contains some Actionscript to communicate with the server but this code would normally be in a seperate file (I embedded it into the MXML to keep things simple).
If you want to find our more about MXML there is a good article Here.
So how does it work?
The main functionality of this application can be found in just a few functions.
The function whoisLookup is where the action occurs. This function takes a domain (or IP Address) as an argument and creates a NetConnection().
private var conn:NetConnection;
private function whoisLookup(domain : String):void
{
conn = new NetConnection();
conn.objectEncoding = ObjectEncoding.AMF0;
conn.connect("http://www.binarystor.com/amfphp/gateway.php");
conn.call( "whoisService.whoisLookup", new Responder(onResult, onFault), domain);
}
function onResult( result : String ) : void
{
mainTxt.text = result;
}
function onFault( fault : String ) : void
{
mainTxt.text = fault;
}
The AMFPHP Whois Service
class whoisService
{ function whoisService ()
{
// Define the methodTable for this class in the constructor
$this->methodTable = array(
"whoisLookup" => array(
"arguments" => array(
"domain" => array("type"=>"string","required"=>true,"description"=>"Domain to lookup")),
"description" => "Perform whois lookup.",
"access" => "remote"
)
);
}function whoisLookup ($domain) {
$whois = new Whois();
$result = $whois->Lookup($domain);
return implode($result['rawdata'],"\n");
}









