![]() |
![]() |
||||||
|
|||||||
| Tags: |
![]() |
|
|||
|
I need to establish a binary socket connection between flex and python socket
server, but I keep receiving the following error in flex: Error #2048: Security sandBox violation http://localhost/test/bin/test/swf cannot load data from 192.168.1.208:12321 I'm [as client] running on openSUSE 11, and I have flash debugger installed following this article: http://www.adobe.com/go/strict_policy_files And my server is running on ubuntu 8.04 The only issue I've noticed that when I comment the following ActionScript line in test.mxml: Security.loadPolicyFile("xmlsocket://"+host+":"+po rt); I receive the following error in policyfiles.txt: [Q]OK: Root-level SWF loaded: http://localhost/test/bin/test.swf OK: Searching for <allow-access-from> in policy files to authorize data loading from resource at xmlsocket://192.168.1.208:12321 by requestor from http://localhost/test/bin/test.swf Warning: Timeout on xmlsocket://192.168.1.208:12321 (at 3 seconds) while waiting for socket policy file. This should not cause any problems, but see http://www.adobe.com/go/strict_policy_files for an explanation. Error: Request for resource at xmlsocket://192.168.1.208:12321 by requestor from http://localhost/test/bin/test.swf is denied due to lack of policy file permissions.[/Q] Otherwise there is no errors produced in policyfiles.txt: [Q]OK: Root-level SWF loaded: http://localhost/test/bin/test.swf OK: Searching for <allow-access-from> in policy files to authorize data loading from resource at xmlsocket://192.168.1.208:12321 by requestor from http://localhost/test/bin/test.swf[/Q] Please HELP! My testing files as follows: Flex Client: test.mxml <?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()"> <mx:Script> <![CDATA[ private var host:String = "192.168.1.208"; private var port:Number = 12321; private var socket:Socket; private function init():void { Security.allowDomain(host); Security.loadPolicyFile("xmlsocket://"+host+":"+po rt); socket = new Socket(); socket.addEventListener(Event.CONNECT, onConnect); socket.addEventListener(Event.CLOSE, onClose); socket.addEventListener(ErrorEvent.ERROR, onError); socket.addEventListener(IOErrorEvent.IO_ERROR, onIOError); socket.addEventListener(SecurityErrorEvent.SECURIT Y_ERROR, onSecurityError); socket.addEventListener(ProgressEvent.SOCKET_DATA, onResponse); try { socket.connect(host, port); outMessage("Trying to connect to "+host+":"+port); } catch (error:Error) { socket.close(); outMessage(error.message); } } public function send(string:String):void { socket.writeUTFBytes(string); socket.flush(); } private function onConnect(event:Event):void { outMessage("Connected to "+host+":"+port); send("date"); } private function onClose(event:Event):void { outMessage("Connection closed"); } private function onError(event:ErrorEvent):void { outMessage("Error "+event.text); } private function onIOError(event:IOErrorEvent):void { outMessage("I/O "+event.text); } private function onSecurityError(event:SecurityErrorEvent):void { outMessage("Security "+event.text); } private function onResponse(event:ProgressEvent):void { var string:String = socket.readUTFBytes(socket.bytesAvailable); outMessage(string); } public function outMessage(msg:String):void { log.htmlText += '<font color="#000099">'+msg+'<br>'; } ]]> </mx:Script> <mx:TextArea id="log" width="400" height="200" x="10" y="10" selectable="false"/> </mx:Application> Server Master Policy File: crossdomain.xml <?xml version="1.0"?> <!DOCTYPE cross-domain-policy SYSTEM "http://www.adobe.com/xml/dtds/cross-domain-policy.dtd"> <cross-domain-policy><site-control permitted-cross-domain-policies="master-only"/><allow-access-from domain="*" to-ports="12321"/></cross-domain-policy> Server Apache Snippet: .htaccess <Files crossdomain.xml> ForceType text/x-cross-domain-policy </Files> Python Socket Server: socketserver.py #!/usr/bin/python import sys class case_selector(Exception): def __init__(self, value): # overridden to ensure we've got a value argument Exception.__init__(self, value) def switch(variable): raise case_selector(variable) def case(value): exclass, exobj, tb = sys.exc_info() if exclass is case_selector and exobj.args[0] == value: return exclass return None def multicase(*values): exclass, exobj, tb = sys.exc_info() if exclass is case_selector and exobj.args[0] in values: return exclass return None import socket class MirrorServer: """Receives text on a line-by-line basis and sends back a reversed version of the same text.""" def __init__(self, port): "Binds the server to the given port." self.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) self.socket.bind(port) #Queue up to five requests before turning clients away. self.socket.listen(5) print "listening to " + str(port) + "\r\n" def run(self): "Handles incoming requests forever." while True: request, client_address = self.socket.accept() #Turn the incoming and outgoing connections into files. input = request.makefile('rb', 0) output = request.makefile('wb', 0) l = True try: while l: l = input.readline().strip() try: switch(l) except case("respond"): output.write("running" + '\r\n') except case("date"): output.write("getDate" + '\r\n') except case("check"): output.write("update" + '\r\n') except case("exit"): request.shutdown(2) except case(l): output.write(l + '\r\n') except socket.error: #Most likely the client disconnected. pass if __name__ == '__main__': import sys if len(sys.argv) < 3: print 'Usage: %s [hostname] [port number]' % sys.argv[0] sys.exit(1) hostname = sys.argv[1] port = int(sys.argv[2]) MirrorServer((hostname, port)).run() |
| Sponsored Links |
![]() |
| Thread Tools | |
| Display Modes | |
|
|
- Contact Us
-|-
Adobe Dreamweaver Forums -|-
Archive -|-
Top -|-Rules/Disclaimer-|-Help/Support-|-Advertise