使用python s的Flash套接字

2024-10-01 09:23:13 发布

您现在位置:Python中文网/ 问答频道 /正文

我尝试使用adobeflash客户端和python服务器之间的套接字发送和获取数据。 Flash客户端:

var serverURL = "se.rv.er.ip";
var xmlSocket:XMLSocket = new XMLSocket();
xmlSocket.connect(serverURL, 50007);

xmlSocket.addEventListener(DataEvent.DATA, onIncomingData);

function onIncomingData(event:DataEvent):void
{
    trace("[" + event.type + "] " + event.data);
}

xmlSocket.send("Hello World");

和python服务器:

^{pr2}$

但是这个代码不起作用。 Python服务器输出:

Connected by ('cl.ie.nt.ip', 3854)
Received '<policy-file-request/>\x00'
received policy

Tags: ip服务器event客户端varpolicyflashse
1条回答
网友
1楼 · 发布于 2024-10-01 09:23:13

如果不需要,就不应该使用套接字模块。当你需要的时候,使用SocketServer,嗯,一个套接字服务器。在

import SocketServer

class MyTCPHandler(SocketServer.BaseRequestHandler):
    def handle(self):
            # self.request is the TCP socket connected to the client
            self.data = self.request.recv(1024).strip()
            print "%s wrote:" % self.client_address[0]
            print self.data
            if '<policy-file-request/>' in self.data:
                print 'received policy'
                conn.send('<?xml version="1.0"?><cross-domain-policy><allow-access-from domain="*" to-ports="50007" /></cross-domain-policy>')
                conn.send('hellow wolrd')

def main():
    # Create the server, binding to localhost on port 9999
    server = SocketServer.TCPServer((HOST, PORT), MyTCPHandler)

    # Activate the server; this will keep running until you
    # interrupt the program with Ctrl-C
    server.serve_forever()

应该是这样的。。在

相关问题 更多 >