How to create a socket server in Python
Like Flash Lite 3, the Flash Player plug-in embedded on Maemo has built-in security restrictions that prevents cross-domain access. If you are planning to implement and use your own socket server or if you are accessing anything remote from a local file, for security, by default Flash Player does not allow an application to access a remote data source from a domain other than the domain from which the application was served. So you have to put a crossdomain.xml file on the server you are accessing.
A crossdomain.xml file is an XML file that provides a way for a server to indicate that its data and documents are available to SWF files served from certain domains, or from all domains. The crossdomain.xml file must be in the web root of the server that the Flex application is contacting.
The following code can be used to overcome the flash player security allowing calls between a local python server (socket engine) and the flash player (web content).
_connector = None
_running = True
_host = '127.0.0.1'
_port = '843'
_maxClient = 999
debug = True
_policyFile = '<?xml version="1.0" encoding="UTF-8"?><cross-domain-policy xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.adobe.com/xml/schemas/PolicyFileSocket.xsd"><allow-access-from domain="*" to-ports="*" secure="false" /><site-control permitted-cross-domain-policies="master-only" /></cross-domain-policy>'
## Trace debugging messages.
# @param aString String to be printed.
def printd( aString ):
_connector = socket.socket( socket.AF_INET, socket.SOCK_STREAM )
_connector.bind ( ( str(_host), int(_port) ) )
_connector.listen ( int(_maxClient) )
_running = True
printd('Running on port ' + _port + ' ... ')
channel, details = _connector.accept()
printd( 'New connection with: ' + str(details) )
channel.setblocking( 1 )
recvData = channel.recv(2000)
if("policy-file-request" in recvData):
printd( 'host: ' + str(details) )
printd( 'port: ' + str(details) )
printd( 'port: ' + str(int(details)) )
You can download the Flex MXML sample and the Python code at code.google.com
FelipeAndrade 13:41, 02 May 2008