You Are Here:

Community: Wiki

This page was last modified on 31 October 2008, at 01:45.

How to create a socket server in Python

From Forum Nokia Wiki

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).

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 Wiki Articles

No related wiki articles found

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia 
RDF Facets: qdcZidentifierQSxhttpE3aE2fE2fwikiE2eforumE2enokiaE2ecomE2findeE78E2ephpE2fE44evelopingE5fPythonE5fApplicationsE5fforE5fMaemoX qdcZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qdcZtypeQUqfntypeZCommunityContentQ qdcZtypeQUqfntypeZE52esourceQ qdcZtypeQUqfntypeZWebpageQ qdcZtypeQUqfntypeZWikiContentQ qdcZtypeQUqmarsZManagedE52esourceQ qdcZtypeQUqwebZInformationE52esourceQ qdcZtypeQUqwebZPageQ qdcZtypeQUqwebZE52esourceQ qdcZtypeQUqrdfsZE52esourceQ qfnZtopicQUqfnTopicZmaemoQ qfnZtopicQUqfnTopicZpythonQ qfnZtypeQUqfntypeZCommunityContentQ qfnZtypeQUqfntypeZE52esourceQ qfnZtypeQUqfntypeZWebpageQ qfnZtypeQUqfntypeZWikiContentQ qfnZuserE5ftagQSxmaemoX qfnZuserE5ftagQSxpythonX qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX qrdfZtypeQUqfnZE45E78cludedFromGeneralE4cistingsQ qrdfZtypeQUqfntypeZCommunityContentQ qrdfZtypeQUqfntypeZE52esourceQ qrdfZtypeQUqfntypeZWebpageQ qrdfZtypeQUqfntypeZWikiContentQ qrdfZtypeQUqmarsZManagedE52esourceQ qrdfZtypeQUqwebZInformationE52esourceQ qrdfZtypeQUqwebZPageQ qrdfZtypeQUqwebZE52esourceQ qrdfZtypeQUqrdfsZE52esourceQ