带有 gevent-websocket 的策略服务器

发布于 2024-12-02 05:13:44 字数 1038 浏览 1 评论 0原文

正在尝试让 gevent-websocket 正常工作,但它没有连接到我的闪存规范策略服务器。我的policy.py如下:

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

但是使用websocket我得到:

[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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

疏忽 2024-12-09 05:13:44

readline() 方法在这里不起作用,因为 Flash 发送一个 '\0',该消息不以换行符终止。

试试这个而不是 readline()

expected = '<policy-file-request>'
s.read(len(expected))

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))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文