Categories: How To | Flash Lite | Python | Maemo
This page was last modified 07:57, 3 May 2008.
How to create a socket server in Python
From Forum Nokia Wiki
Like Flash Lite 3, the Flash Player plugin 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).
import socket _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 ): if debug: print aString _connector = socket.socket( socket.AF_INET, socket.SOCK_STREAM ) _connector.bind ( ( str(_host), int(_port) ) ) _connector.listen ( int(_maxClient) ) _running = True while _running: printd('Running on port ' + _port + ' ... ') channel, details = _connector.accept() if _running: printd( 'New connection with: ' + str(details) ) channel.setblocking( 1 ) recvData = channel.recv(2000) if("policy-file-request" in recvData): channel.send(_policyFile) printd( 'host: ' + str(details[0]) ) printd( 'port: ' + str(details[1]) ) printd( 'port: ' + str(int(details[1])) ) channel.close()
Download
You can download the Flex MXML sample and the Python code at code.google.com
Autor
FelipeAndrade 13:41, 02 May 2008
| Related Discussions | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Trouble with HTTPS | jranki | Python | 8 | 2005-07-05 11:13 |
| j2me支持 udp socket 吗 ? | RongJia | Other Programming Discussion 关于其他编程技术的讨论 | 5 | 2005-09-16 06:11 |
| Launching browser from python | jkaperi | Python | 10 | 2008-03-23 05:30 |
| question on BT programming | hawlman | Bluetooth Technology | 10 | 2006-04-11 16:55 |
| problem connecting to mobile web server. | lb213_2000 | Mobile Web Server | 2 | 2007-11-14 07:57 |
