简体   繁体   中英

Flash client XMLsocket can't connect to python server

I have a flash client use XMLsocket to connect python server like this:

Security.loadPolicyFile("xmlsocket://*.*.*.*:843");
socket = new XMLSocket();
socket.connect('*.*.*.*', 50000);
socket.send('hello world');

I use this python script to send security file

#security.py
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(('0.0.0.0', 843))

s.listen(5)
print('Start...')

def link(sock, addr):
    print('Accept new connection from %s:%s...' % addr)
    while True:
        data = sock.recv(1024)
        str = data.decode('utf-8')[:22]
        if str=='<policy-file-request/>':
            print('!!!!!!!')
            sock.send(b'<?xml version="1.0"?>')
            sock.send(b'<cross-domain-policy>')
            sock.send(b'<allow-access-from domain="*" to-ports="50000" />')
            sock.send(b'</cross-domain-policy>\0')
            sock.close()
            break
    print('')

while True:
    sock, addr = s.accept()
    t = threading.Thread(target=link, args=(sock, addr))
    t.start()

and use this to receive messages from client:

#server.py
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(('0.0.0.0', 50000))

s.listen(5)
print('Waiting for connection...')

def tcplink(sock, addr):
    print('Accept new connection from %s:%s...' % addr)
    while True:
        data = sock.recv(1024)
        print(data.decode('utf-8'))

while True:
    sock, addr = s.accept()
    t = threading.Thread(target=tcplink, args=(sock, addr))
    t.start()

when these scripts run,security.py outputs:

Start...
Accept new connection from *.*.*.*....
!!!!!!!

but server.py outputs nothing except this:

Waiting for connection...

and the debug of flash outputs nothing neither

it seems flash received security file successfully,but the XMLsocket.connect failed?

Hard to say what's wrong here but I'd guess there's still a security problem somewhere. Why don't you add event listeners to the socket connection and see if you will get any error messages? Take a look here at the bottom of the page for some event listener examples: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/XMLSocket.html .

And I guess you have already carefully read this, maybe it will give you some hints: http://help.adobe.com/en_US/as3/dev/WS5b3ccc516d4fbf351e63e3d118a9b90204-7c60.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM