當前位置: 首頁>>代碼示例>>Python>>正文


Python socketserver.BaseRequestHandler方法代碼示例

本文整理匯總了Python中socketserver.BaseRequestHandler方法的典型用法代碼示例。如果您正苦於以下問題:Python socketserver.BaseRequestHandler方法的具體用法?Python socketserver.BaseRequestHandler怎麽用?Python socketserver.BaseRequestHandler使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在socketserver的用法示例。


在下文中一共展示了socketserver.BaseRequestHandler方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: handle

# 需要導入模塊: import socketserver [as 別名]
# 或者: from socketserver import BaseRequestHandler [as 別名]
def handle(self):
        # 創建一個鏈接,繼承於socketserver中的BaseRequestHandler類
        conn = self.request
        conn.sendall(bytes("Welcome to login...", encoding="utf-8"))
        print("Client connect...")
        while True:
            # 輸出等待客戶端發送內容
            print("Waitting for recving message...")
            # 接收客戶端發送過來的內容
            message = conn.recv(1024)
            # 輸出用戶發送過來的內容
            print(message.decode('utf-8'))
            # 如果用戶輸入的是q
            if message == "exit":
                break
            # 給客戶端發送內容
            data = input("Reply message:")
            conn.sendall(data.encode('utf-8')) 
開發者ID:lyonyang,項目名稱:blogs,代碼行數:20,代碼來源:multi_socketserver_server.py

示例2: 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

示例3: requestHandlerFactory

# 需要導入模塊: import socketserver [as 別名]
# 或者: from socketserver import BaseRequestHandler [as 別名]
def requestHandlerFactory(data_handler):
    class ThreadedTCPRequestHandler(socketserver.BaseRequestHandler):
        def __init__(self, *args):
            self.data_handler = data_handler
            super().__init__(*args)

        def handle(self):
            while True:
                data = receive(self.request)

                if data:
                    response = self.data_handler(self.request, data)

                    if response:
                        send(self.request, response)
                else:
                    break

            log('Handler Exiting')

    return ThreadedTCPRequestHandler 
開發者ID:itsapi,項目名稱:pycraft,代碼行數:23,代碼來源:network.py

示例4: 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

示例5: __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

示例6: __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:Microvellum,項目名稱:Fluid-Designer,代碼行數:6,代碼來源:rpc.py

示例7: __init__

# 需要導入模塊: import socketserver [as 別名]
# 或者: from socketserver import BaseRequestHandler [as 別名]
def __init__(self, request, clientaddress, server ):
        self.locals = {}
        self.globals = globals().copy()
        self.wfile = request.makefile("w")
        self.rfile = request.makefile("r")
        socketserver.BaseRequestHandler.__init__(self, request, clientaddress,
                                                 server ) 
開發者ID:jlachowski,項目名稱:clonedigger,代碼行數:9,代碼來源:monserver.py

示例8: __init__

# 需要導入模塊: import socketserver [as 別名]
# 或者: from socketserver import BaseRequestHandler [as 別名]
def __init__(self, request, client_address, server):
        socketserver.BaseRequestHandler.__init__(self, request, client_address, server) 
開發者ID:integeruser,項目名稱:on-pwning,代碼行數:4,代碼來源:service.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:Coalfire-Research,項目名稱:Slackor,代碼行數:11,代碼來源:socksserver.py

示例10: __init__

# 需要導入模塊: import socketserver [as 別名]
# 或者: from socketserver import BaseRequestHandler [as 別名]
def __init__(self, globalData: GlobalData,
                 serverAddress: str,
                 RequestHandlerClass: socketserver.BaseRequestHandler):

        # get reference to global data object
        self.globalData = globalData

        socketserver.TCPServer.__init__(self,
                                        serverAddress,
                                        RequestHandlerClass)


# this class is used for incoming local client connections (i.e., web page) 
開發者ID:sqall01,項目名稱:alertR,代碼行數:15,代碼來源:server.py

示例11: __init__

# 需要導入模塊: import socketserver [as 別名]
# 或者: from socketserver import BaseRequestHandler [as 別名]
def __init__(self,
                 globalData: GlobalData,
                 serverAddress: Tuple[str, int],
                 RequestHandlerClass: Type[socketserver.BaseRequestHandler]):

        # get reference to global data object
        self.globalData = globalData

        socketserver.TCPServer.__init__(self,
                                        serverAddress,
                                        RequestHandlerClass)


# this class is used for incoming client connections 
開發者ID:sqall01,項目名稱:alertR,代碼行數:16,代碼來源:server.py

示例12: 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;未經允許,請勿轉載。