How to create a socket server in Python

From Nokia Developer Wiki
Jump to: navigation, search

Archived.pngArchived: This article is archived because it is not considered relevant for third-party developers creating commercial solutions today. If you think this article is still relevant, let us know by adding the template {{ReviewForRemovalFromArchive|user=~~~~|write your reason here}}.

The article is believed to be still valid for the original topic scope.

Article Metadata
Created: felipebzr (02 May 2008)
Last edited: lpvalente (29 Mar 2013)

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 = ''
_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):
printd( 'host: ' + str(details[0]) )
printd( 'port: ' + str(details[1]) )
printd( 'port: ' + str(int(details[1])) )


You can download the Flex MXML sample and the Python code at code.google.com


FelipeAndrade 13:41, 02 May 2008

This page was last modified on 29 March 2013, at 21:21.
70 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.


Thank you!

We appreciate your feedback.