Skip to content

Instantly share code, notes, and snippets.

@jizhang
Created July 19, 2012 16:29
Show Gist options
  • Save jizhang/3145114 to your computer and use it in GitHub Desktop.
Save jizhang/3145114 to your computer and use it in GitHub Desktop.
simple socket server
import SocketServer
class ThreadedTCPRequestHandler(SocketServer.BaseRequestHandler):
def handle(self):
self.request.sendall("""
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE cross-domain-policy SYSTEM "http://www.adobe.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy><site-control permitted-cross-domain-policies="all"/>
<allow-access-from domain="*.aifang.com" to-ports="*" />
<allow-access-from domain="*.pages.aifcdn.com" to-ports="*" />
<allow-access-from domain="*.aifcdn.com" to-ports="*" />
<allow-access-from domain="anjuke.adsame.com" to-ports="*" />
<allow-access-from domain="anjuke.adsame.com" to-ports="*" />
</cross-domain-policy>
""")
class ThreadedTCPServer(SocketServer.ThreadingMixIn, SocketServer.TCPServer):
allow_reuse_address = True
if __name__ == "__main__":
HOST, PORT = "", 843
server = ThreadedTCPServer((HOST, PORT), ThreadedTCPRequestHandler)
try:
server.serve_forever()
except KeyboardInterrupt:
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment