我想把我的数据库连接传递给EchoHandler类,但是我无法弄清楚如何实现或访问EchoHandler类。
class EchoHandler(SocketServer.StreamRequestHandler): def handle(self): print self.client_address, 'connected'
if __name__ == '__main__': conn = MySQLdb.connect (host = "10.0.0.5", user = "user", passwd = "pass", db = "database")
SocketServer.ForkingTCPServer.allow_reuse_address = 1
server = SocketServer.ForkingTCPServer(('10.0.0.6', 4242), EchoHandler)
print "服务器正在监听 localhost:4242..." try: server.allow_reuse_address server.serve_forever() except KeyboardInterrupt: print "\n退出..."
MyServer.__init__
中不使用super().__init__(...)
呢? - Johannes Bittner