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


Python SocketServer.BaseRequestHandler方法代码示例

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


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

示例1: run_tcp

# 需要导入模块: import SocketServer [as 别名]
# 或者: from SocketServer import BaseRequestHandler [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 BaseRequestHandler [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: __init__

# 需要导入模块: import SocketServer [as 别名]
# 或者: from SocketServer import BaseRequestHandler [as 别名]
def __init__(self):
        
        self.CryptoArgs =  dict()
        self.CryptoArgs['INITKEY']       = "My initial key"
        self.CryptoArgs['DEBUG']         = False
        self.CryptoArgs['CYCLES']        = 3
        self.CryptoArgs['BLOCK_SZ']      = 20
        self.CryptoArgs['KEY_ADV']       = 5
        self.CryptoArgs['KEY_MAGNITUDE'] = 1
        
        SimpleCryptSocketExt.__init__(self, self.CryptoArgs)
        
        self.InBoundData    = ""
        self.OutBoundData   = ""
        
        #self.salt_method  = "Simple"
        #self.salt_method  = "NTP"
        #self.salt_method  = "PrevData"
        
    
#####################################################################################            
   
    
#####################################################################################
#Class to handle Server coms overriding BaseRequestHandler handle method 
开发者ID:ActiveState,项目名称:code,代码行数:27,代码来源:recipe-577212.py

示例4: setUp

# 需要导入模块: import SocketServer [as 别名]
# 或者: from SocketServer import BaseRequestHandler [as 别名]
def setUp(self):
        self.registry = CollectorRegistry()

        self.data = ''

        class TCPHandler(SocketServer.BaseRequestHandler):
            def handle(s):
                self.data = s.request.recv(1024)

        server = SocketServer.TCPServer(('', 0), TCPHandler)

        class ServingThread(threading.Thread):
            def run(self):
                server.handle_request()
                server.socket.close()

        self.t = ServingThread()
        self.t.start()

        # Explicitly use localhost as the target host, since connecting to 0.0.0.0 fails on Windows
        address = ('localhost', server.server_address[1])
        self.gb = GraphiteBridge(address, self.registry, _timer=fake_timer) 
开发者ID:prometheus,项目名称:client_python,代码行数:24,代码来源:test_graphite_bridge.py

示例5: __init__

# 需要导入模块: import SocketServer [as 别名]
# 或者: from SocketServer import BaseRequestHandler [as 别名]
def __init__(self, request, client_address, server):
		SocketServer.BaseRequestHandler.__init__(self, request, client_address, server)
		return 
开发者ID:SecPi,项目名称:SecPi,代码行数:5,代码来源:tcpportlistener.py

示例6: __init__

# 需要导入模块: import SocketServer [as 别名]
# 或者: from SocketServer import BaseRequestHandler [as 别名]
def __init__(self, *args, **kwargs):
		self.server = args[2]
		self.chain_host = self.server.remote_server[0]
		self.chain_port = self.server.remote_server[1]
		self.ssh_transport = self.server.ssh_transport
		socketserver.BaseRequestHandler.__init__(self, *args, **kwargs) 
开发者ID:rsmusllp,项目名称:king-phisher,代码行数:8,代码来源:ssh_forward.py

示例7: __init__

# 需要导入模块: import SocketServer [as 别名]
# 或者: from SocketServer import BaseRequestHandler [as 别名]
def __init__(self, request, client_address, server):
		self.nick = None		# Client's currently registered nickname
		self.host = client_address	# Client's hostname / ip.
		self.status = 0			# Client's status (0=available, 1=away, 2=playing)
		self.clienttype = None		# can be: player(fba), spectator(fba) or client
		self.previous_status = None	# Client's previous status (0=available, 1=away, 2=playing)
		self.opponent = None		# Client's opponent
		self.quark = None		# Client's quark (in-game uri)
		self.fbaport = 0		# Emulator's fbaport
		self.side = 0			# Client's side: 1=P1, 2=P2 (0=spectator before savestate, 3=spectator after savestate)
		self.port = 6009		# Client's port
		self.city = "null"		# Client's city
		self.country = "null"		# Client's country
		self.cc = "null"		# Client's country code
		self.lastmsgtime = 0		# timestamp of the last chat message
		self.challengetime = 0		# timestamp of the last challenge
		self.lastmsg = ''		# last chat message
		self.spamhit = 0		# how many times has been warned for spam
		self.useports = False		# set to true when we have potential problems with NAT traversal
		self.version = 0		# client version
		self.warnmsg = ''		# Warning message (shown after match)
		self.turboflag = 0		# turbo flag helper
		self.send_queue = []		# Messages to send to client (strings)
		self.channel = GGPOChannel("lobby",'', "The Lobby")	# Channel the client is in
		self.challenging = {}		# users (GGPOClient instances) that this client is challenging by host

		try:
			set_keepalive_linux(request)
		except:
			pass
		SocketServer.BaseRequestHandler.__init__(self, request, client_address, server) 
开发者ID:poliva,项目名称:ggposrv,代码行数:33,代码来源:ggposrv.py

示例8: __init__

# 需要导入模块: import SocketServer [as 别名]
# 或者: from SocketServer import BaseRequestHandler [as 别名]
def __init__(self, sock, addr, svr):
        svr.current_handler = self ## cgt xxx
        SocketIO.__init__(self, sock)
        SocketServer.BaseRequestHandler.__init__(self, sock, addr, svr) 
开发者ID:dxwu,项目名称:BinderFilter,代码行数:6,代码来源:rpc.py

示例9: __init__

# 需要导入模块: import SocketServer [as 别名]
# 或者: from SocketServer import BaseRequestHandler [as 别名]
def __init__(self, request, client_address, server):
        self.__socksServer = server
        self.__ip, self.__port = client_address
        self.__connSocket= request
        self.__socksVersion = 5
        self.targetHost = None
        self.targetPort = None
        self.__NBSession= None
        SocketServer.BaseRequestHandler.__init__(self, request, client_address, server) 
开发者ID:eth0izzle,项目名称:cracke-dit,代码行数:11,代码来源:socksserver.py

示例10: create_length_prefixed_tcp_handler

# 需要导入模块: import SocketServer [as 别名]
# 或者: from SocketServer import BaseRequestHandler [as 别名]
def create_length_prefixed_tcp_handler():
    queue = Queue()
    class LengthPrefixedTcpHandler(BaseRequestHandler):
        def handle(self):
            #msg = _read_length_prefixed_msg(self.request)
            # this will run inside a new thread
            self.request.send("hello\n")
            while True:
                b = _read_n_bytes(self.request, 10)
                self.request.send("you sent: %s" % b)
                queue.put(b)

    return queue, LengthPrefixedTcpHandler 
开发者ID:OpenState-SDN,项目名称:ryu,代码行数:15,代码来源:tcp.py

示例11: tcp_server

# 需要导入模块: import SocketServer [as 别名]
# 或者: from SocketServer import BaseRequestHandler [as 别名]
def tcp_server(request):
    """Start a TCP server in a thread."""
    data = list()

    class Getter(object):
        def __init__(self, t, s, d):
            self.thread = t
            self.server = s
            self._data = d

        @property
        def data(self):
            for i in range(50):
                if self._data:
                    break
                time.sleep(0.1)
            return self._data

    class TCPHandler(socketserver.BaseRequestHandler):
        def handle(self):
            data.append(self.request.recv(25))

    server = socketserver.TCPServer(('', 0), TCPHandler)
    thread = threading.Thread(target=server.serve_forever)
    thread.daemon = True
    thread.start()

    def fin():
        server.socket.close()
        server.shutdown()
        for _ in range(5):
            if not thread.is_alive():
                break
            time.sleep(0.2)
        assert not thread.is_alive()
    request.addfinalizer(fin)

    return Getter(thread, server, data) 
开发者ID:Robpol86,项目名称:libnl,代码行数:40,代码来源:conftest.py

示例12: __init__

# 需要导入模块: import SocketServer [as 别名]
# 或者: from SocketServer import BaseRequestHandler [as 别名]
def __init__ (self, request, client_address, server):
        self.logger = logging.getLogger('EchoRequestHandler')
        self.logger.debug('__init__')
        SocketServer.BaseRequestHandler.__init__(self, request, client_address, server)
        return 
开发者ID:soarpenguin,项目名称:python-scripts,代码行数:7,代码来源:EchoServer.py

示例13: setup

# 需要导入模块: import SocketServer [as 别名]
# 或者: from SocketServer import BaseRequestHandler [as 别名]
def setup(self):
        self.logger.debug('setup')
        return SocketServer.BaseRequestHandler.setup(self) 
开发者ID:soarpenguin,项目名称:python-scripts,代码行数:5,代码来源:EchoServer.py

示例14: finish

# 需要导入模块: import SocketServer [as 别名]
# 或者: from SocketServer import BaseRequestHandler [as 别名]
def finish(self):
        self.logger.debug('finish')
        return SocketServer.BaseRequestHandler.finish(self) 
开发者ID:soarpenguin,项目名称:python-scripts,代码行数:5,代码来源:EchoServer.py

示例15: test_logging

# 需要导入模块: import SocketServer [as 别名]
# 或者: from SocketServer import BaseRequestHandler [as 别名]
def test_logging(self):
        """
        Test logging.
        """

        messages = []

        class SyslogHandler(socketserver.BaseRequestHandler):
            """
            Save received messages.
            """

            def handle(self):
                messages.append(self.request[0].strip().decode())

        syslog = socketserver.UDPServer(('0.0.0.0', 0), SyslogHandler)
        try:
            threading.Thread(target=syslog.serve_forever).start()

            env = os.environ.copy()
            env['SYSLOG_SERVER'] = syslog.server_address[0]
            env['SYSLOG_PORT'] = str(syslog.server_address[1])
            env['SYSLOG_PROTO'] = 'udp'

            mydir = os.path.dirname(__file__)

            supervisor = subprocess.Popen(
                ['supervisord', '-c', os.path.join(mydir, 'supervisord.conf')],
                env=env,
            )
            try:

                sleep(3)

                pid = subprocess.check_output(
                    ['supervisorctl', 'pid', 'messages']
                ).decode().strip()

                sleep(8)

                self.assertEqual(
                    list(map(strip_volatile, messages)),
                    ['<14>DATE HOST messages[{pid}]: Test {i} \n\x00'.format(
                        pid=pid,
                        i=i)
                     for i in range(4)]
                )
            finally:
                supervisor.terminate()

        finally:
            syslog.shutdown() 
开发者ID:infoxchange,项目名称:supervisor-logging,代码行数:54,代码来源:test_supervisor_logging.py


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