当前位置: 首页>>代码示例>>Python>>正文


Python SocketServer.ThreadingMixIn方法代码示例

本文整理汇总了Python中SocketServer.ThreadingMixIn方法的典型用法代码示例。如果您正苦于以下问题:Python SocketServer.ThreadingMixIn方法的具体用法?Python SocketServer.ThreadingMixIn怎么用?Python SocketServer.ThreadingMixIn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SocketServer的用法示例。


在下文中一共展示了SocketServer.ThreadingMixIn方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: run_tcp

# 需要导入模块: import SocketServer [as 别名]
# 或者: from SocketServer import ThreadingMixIn [as 别名]
def run_tcp(realport, fakeport, handler):
	class SingleTCPHandler(SocketServer.BaseRequestHandler):
		def handle(self):
			srcaddr, srcport = self.request.getpeername()
			print("Connection from {}:{}".format(srcaddr, srcport))
			handler(self.request, fakeport)

	class SimpleServer(SocketServer.ThreadingMixIn, SocketServer.TCPServer):
		daemon_threads = True
		allow_reuse_address = True

		def __init__(self, server_address, RequestHandlerClass):
			SocketServer.TCPServer.__init__(self, server_address, RequestHandlerClass)

	server = SimpleServer(('127.0.0.1', realport), SingleTCPHandler)
	try:
		server.serve_forever()
	except KeyboardInterrupt:
		sys.exit(0) 
开发者ID:fabio-d,项目名称:honeypot,代码行数:21,代码来源:testrun.py

示例2: run_udp

# 需要导入模块: import SocketServer [as 别名]
# 或者: from SocketServer import ThreadingMixIn [as 别名]
def run_udp(realport, fakeport, handler):
	class SingleUDPHandler(SocketServer.BaseRequestHandler):
		def handle(self):
			srcaddr, srcport = self.client_address
			print("Packet from {}:{}".format(srcaddr, srcport))
			handler(self.request[1], self.request[0], self.client_address, fakeport)

	class SimpleServer(SocketServer.ThreadingMixIn, SocketServer.UDPServer):
		daemon_threads = True

		def __init__(self, server_address, RequestHandlerClass):
			SocketServer.UDPServer.__init__(self, server_address, RequestHandlerClass)

	server = SimpleServer(('127.0.0.1', realport), SingleUDPHandler)
	try:
		server.serve_forever()
	except KeyboardInterrupt:
		sys.exit(0) 
开发者ID:fabio-d,项目名称:honeypot,代码行数:20,代码来源:testrun.py

示例3: _http_python2

# 需要导入模块: import SocketServer [as 别名]
# 或者: from SocketServer import ThreadingMixIn [as 别名]
def _http_python2(self, listen_ssl=False):
        """Listen for HTTP connections with Python 2."""
        class ThreadingSimpleServer(SocketServer.ThreadingMixIn,
                                    BaseHTTPServer.HTTPServer):
            pass
        server = ThreadingSimpleServer(self.listen_socket,
                                       DeenHTTPRequestHandler)
        os.chdir(self.serving_directory)
        message = 'Serving HTTP at port ' + str(self.listen_port)
        if listen_ssl:
            message += ' (SSL)'
        print(message)
        try:
            while 1:
                sys.stdout.flush()
                server.handle_request()
        except KeyboardInterrupt:
            server.socket.close() 
开发者ID:takeshixx,项目名称:deen,代码行数:20,代码来源:plugin_listener.py

示例4: start_server

# 需要导入模块: import SocketServer [as 别名]
# 或者: from SocketServer import ThreadingMixIn [as 别名]
def start_server():
    server_address = ('127.0.0.1', 0)

    class DaemonThreadingMixIn(ThreadingMixIn):
        daemon_threads = True

    class ThreadedHTTPServer(DaemonThreadingMixIn, HTTPServer):
        """Handle requests in a separate thread."""

    # not actually going to do anything with this server, so a
    # do-nothing handler is reasonable
    httpd = ThreadedHTTPServer(server_address, BaseHTTPRequestHandler)
    server_thread = threading.Thread(target=httpd.serve_forever)
    server_thread.daemon = True
    server_thread.start()
    return httpd, server_thread 
开发者ID:Acmesec,项目名称:CTFCrackTools-V2,代码行数:18,代码来源:test_socket_jy.py

示例5: tcp_test_main

# 需要导入模块: import SocketServer [as 别名]
# 或者: from SocketServer import ThreadingMixIn [as 别名]
def tcp_test_main():
    class Server(ThreadingMixIn, TCPServer):
        pass

    queue, Handler = create_length_prefixed_tcp_handler()

    server = Server(('localhost', 12345), Handler)
    server.allow_reuse_address = True

    server.serve_forever() 
开发者ID:OpenState-SDN,项目名称:ryu,代码行数:12,代码来源:tcp.py


注:本文中的SocketServer.ThreadingMixIn方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。