Adobe Dreamweaver Forums



Last 10 THreads :         Changing RadioButton Label (Last Post : justintoflex - Replies : 2 - Views : 5 )           »          Table Borders MIssing in JavaHelp (Last Post : soxmann - Replies : 3 - Views : 8 )           »          Clock .getUTC not working (Last Post : bolszo - Replies : 2 - Views : 3 )           »          cfimage error (Last Post : masoud_amen - Replies : 2 - Views : 3 )           »          Dragging components (Last Post : hsfrey - Replies : 2 - Views : 4 )           »          Is file too large? (Last Post : tweaked_eye - Replies : 0 - Views : 1 )           »          Could not find the included template (Last Post : azuro28 - Replies : 2 - Views : 3 )           »          problems linking PDFs (Last Post : Mantzi - Replies : 0 - Views : 1 )           »          flash loader reappears after movie plays (Last Post : lyshamo - Replies : 3 - Views : 4 )           »          How to turn IMAGE into MOVIECLIP??? (Last Post : Snufferson - Replies : 7 - Views : 8 )           »         


Home Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
User Info Statistics
Go Back   Adobe Dreamweaver Forums > Other Macromedia/Adobe Products > Flex
 
Tags:



Reply
  #1 (permalink)  
Old 12-01-2008, 12:23 PM
xvisage
 
Posts: n/a
Diggs:
Default Flex - Python Socket Server

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



Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



© Camley Interactive (camley.info) 2008 - all logos and images are copywrite their respective owners.
Proud member of the Camley Interactive Network
All times are GMT. The time now is 11:43 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0 ©2007, Crawlability, Inc.
Cheap Car Insurance - Compare Motor Insurance
Endsleigh Car Insurance Natwest Car Insurance
More Than Car Insurance Norwich Union Car Insurance
Prudential Car Insurance Zurich Car Insurance
Inactive Reminders By Mished.co.uk