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
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))
精彩评论