Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Policy Server with gevent-websocket

working on trying to get gevent-websocket working and it's not connecting to my policy server for the flash specification. My policy.py is as follows:

from gevent.server import StreamServer

policy = """<?xml version="1.0" encoding="UTF-8"?>
<cross-domain-policy>
  <site-control permitted-cross-domain-policies="master-only"/>
 <allow-access-from domain="*" to-ports="*" secure="false"/>
</cross-domain-policy>\0"""

def handle(sock, address):
s = sock.makefile()
while True:
    msg = s.readline()
    if not msg:
        print("Client disconnected (%s:%s)" % address)
        break
    else:
        sock.sendall(policy)
        print("Client connected, served policy (%s:%s)" % address)

server = StreamServer(('0.0.0.0', 843), handle)
server.serve_forever()

Yet with websocket I'm getting:

[WebSocket] policy file: xmlsocket://localhost:843
[WebSocket] cannot connect to Web Socket server at ws://localhost:8065 (SecurityError: Error #2048) make sure the server is running and Flash socket policy file is correctly placed
[WebSocket] close
like image 998
d0ctor Avatar asked Nov 04 '22 15:11

d0ctor


1 Answers

the readline() method won't work here, because Flash sends a '<policy-file-request/>\0' which is not terminated by newline.

Try this instead of readline():

expected = '<policy-file-request>'
s.read(len(expected))
like image 134
Denis Avatar answered Nov 15 '22 08:11

Denis