分类: Python

apache+mod_python+django+pyamf与flash通信(@centos)

装apache & mod_python可以通过yum安装,python是linux自带的。
django可以去官方网站
下载https://www.djangoproject.com/download/
安装https://docs.djangoproject.com/en/dev/intro/install/

目录结构-以我自己的习惯:

#mkdir /data
#cd /data
#django-admin.py startproject myproj
#cd myproj
#django-admin.py startapp amfgateway

好了该建立的项目和应用都建好了现在要配置下。

#vi /data/myproj/urls.py
——————————————————————
from django.conf.urls.defaults import patterns, include, url
urlpatterns = patterns(”,

url(r’^myproj/’, include(‘myproj.amfgateway.urls’)),
)
——————————————————————

#vi /data/myproj/amfgateway/urls.py
——————————————————————

from django.conf.urls.defaults import patterns, include, url

urlpatterns = patterns(‘amfgateway.views’,
url(r’amfgateway/$’, ‘echoGateway’),
)

——————————————————————

#vi /data/myproj/amfgateway/view.py
——————————————————————
# Create your views here.

from pyamf.remoting.gateway.django import DjangoGateway

def echo(request, data):
return data

services = {
‘echo’: echo
# could include other functions as well
}

echoGateway = DjangoGateway(services)

——————————————————————

随后,配置apache

#vi /etc/httpd/conf/httpd.conf

在文件最后添加
——————————————————————
NameVirtualHost *:80


DocumentRoot /www
ErrorLog logs/error_log
CustomLog logs/access_log common


SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE myproj.settings
PythonDebug On
PythonPath “[‘/data’, ‘/data/myproj’] + sys.path”


——————————————————————

最后
写个as试试链接下

Main.as
——————————————————————
package
{
import flash.net.Responder;
import flash.net.NetConnection;
import flash.display.Sprite;

public class Main extends Sprite
{
// Gateway connection object
private var gateway:NetConnection;

public function Main()
{
// Setup connection
gateway = new NetConnection();

// Connect to gateway
gateway.connect( “http://192.168.1.250/myproj/amfgateway/” );

// This var holds the data we want to pass to the remote service.
var param:String = “Hello World!\n”;

// Set responder property to the object and methods that will receive the
// result or fault condition that the service returns.
var responder:Responder = new Responder( onResult, onFault );

// Call remote service to fetch data
trace(“Start call”);
gateway.call( “echo”, responder, param );
}

// Result handler method
private function onResult( result:Object ): void {
trace( result +”\n”);// prints “Hello World!”
}
// Fault handler method displays error message
private function onFault( error:Object ): void {
// Notify the user of the problem

// status_txt.text = “Remoting error: \n”;
for (var d:String in error) {
trace( error[d] + “\n” );
}
}
}
}

——————————————————————

Share