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


Python tcpserver.TCPServer方法代碼示例

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


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

示例1: test_wait_for_handshake_callback

# 需要導入模塊: from tornado import tcpserver [as 別名]
# 或者: from tornado.tcpserver import TCPServer [as 別名]
def test_wait_for_handshake_callback(self):
        test = self
        handshake_future = Future()

        class TestServer(TCPServer):
            def handle_stream(self, stream, address):
                # The handshake has not yet completed.
                test.assertIsNone(stream.socket.cipher())
                self.stream = stream
                stream.wait_for_handshake(self.handshake_done)

            def handshake_done(self):
                # Now the handshake is done and ssl information is available.
                test.assertIsNotNone(self.stream.socket.cipher())
                handshake_future.set_result(None)

        yield self.connect_to_server(TestServer)
        yield handshake_future 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:20,代碼來源:iostream_test.py

示例2: test_wait_for_handshake_future

# 需要導入模塊: from tornado import tcpserver [as 別名]
# 或者: from tornado.tcpserver import TCPServer [as 別名]
def test_wait_for_handshake_future(self):
        test = self
        handshake_future = Future()

        class TestServer(TCPServer):
            def handle_stream(self, stream, address):
                test.assertIsNone(stream.socket.cipher())
                test.io_loop.spawn_callback(self.handle_connection, stream)

            @gen.coroutine
            def handle_connection(self, stream):
                yield stream.wait_for_handshake()
                handshake_future.set_result(None)

        yield self.connect_to_server(TestServer)
        yield handshake_future 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:18,代碼來源:iostream_test.py

示例3: test_wait_for_handshake_already_connected

# 需要導入模塊: from tornado import tcpserver [as 別名]
# 或者: from tornado.tcpserver import TCPServer [as 別名]
def test_wait_for_handshake_already_connected(self):
        handshake_future = Future()

        class TestServer(TCPServer):
            def handle_stream(self, stream, address):
                self.stream = stream
                stream.wait_for_handshake(self.handshake_done)

            def handshake_done(self):
                self.stream.wait_for_handshake(self.handshake2_done)

            def handshake2_done(self):
                handshake_future.set_result(None)

        yield self.connect_to_server(TestServer)
        yield handshake_future 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:18,代碼來源:iostream_test.py

示例4: test_handle_stream_native_coroutine

# 需要導入模塊: from tornado import tcpserver [as 別名]
# 或者: from tornado.tcpserver import TCPServer [as 別名]
def test_handle_stream_native_coroutine(self):
        # handle_stream may be a native coroutine.

        class TestServer(TCPServer):
            async def handle_stream(self, stream, address):
                stream.write(b"data")
                stream.close()

        sock, port = bind_unused_port()
        server = TestServer()
        server.add_socket(sock)
        client = IOStream(socket.socket())
        yield client.connect(("localhost", port))
        result = yield client.read_until_close()
        self.assertEqual(result, b"data")
        server.stop()
        client.close() 
開發者ID:opendevops-cn,項目名稱:opendevops,代碼行數:19,代碼來源:tcpserver_test.py

示例5: test_single

# 需要導入模塊: from tornado import tcpserver [as 別名]
# 或者: from tornado.tcpserver import TCPServer [as 別名]
def test_single(self):
        # As a sanity check, run the single-process version through this test
        # harness too.
        code = textwrap.dedent(
            """
            from tornado.ioloop import IOLoop
            from tornado.tcpserver import TCPServer

            server = TCPServer()
            server.listen(0, address='127.0.0.1')
            IOLoop.current().run_sync(lambda: None)
            print('012', end='')
        """
        )
        out = self.run_subproc(code)
        self.assertEqual("".join(sorted(out)), "012") 
開發者ID:opendevops-cn,項目名稱:opendevops,代碼行數:18,代碼來源:tcpserver_test.py

示例6: test_advanced

# 需要導入模塊: from tornado import tcpserver [as 別名]
# 或者: from tornado.tcpserver import TCPServer [as 別名]
def test_advanced(self):
        code = textwrap.dedent(
            """
            from tornado.ioloop import IOLoop
            from tornado.netutil import bind_sockets
            from tornado.process import fork_processes, task_id
            from tornado.ioloop import IOLoop
            from tornado.tcpserver import TCPServer

            sockets = bind_sockets(0, address='127.0.0.1')
            fork_processes(3)
            server = TCPServer()
            server.add_sockets(sockets)
            IOLoop.current().run_sync(lambda: None)
            print(task_id(), end='')
        """
        )
        out = self.run_subproc(code)
        self.assertEqual("".join(sorted(out)), "012") 
開發者ID:opendevops-cn,項目名稱:opendevops,代碼行數:21,代碼來源:tcpserver_test.py

示例7: test_wait_for_handshake_future

# 需要導入模塊: from tornado import tcpserver [as 別名]
# 或者: from tornado.tcpserver import TCPServer [as 別名]
def test_wait_for_handshake_future(self):
        test = self
        handshake_future = Future()  # type: Future[None]

        class TestServer(TCPServer):
            def handle_stream(self, stream, address):
                test.assertIsNone(stream.socket.cipher())
                test.io_loop.spawn_callback(self.handle_connection, stream)

            @gen.coroutine
            def handle_connection(self, stream):
                yield stream.wait_for_handshake()
                handshake_future.set_result(None)

        yield self.connect_to_server(TestServer)
        yield handshake_future 
開發者ID:opendevops-cn,項目名稱:opendevops,代碼行數:18,代碼來源:iostream_test.py

示例8: test_handle_stream_native_coroutine

# 需要導入模塊: from tornado import tcpserver [as 別名]
# 或者: from tornado.tcpserver import TCPServer [as 別名]
def test_handle_stream_native_coroutine(self):
        # handle_stream may be a native coroutine.

        namespace = exec_test(globals(), locals(), """
        class TestServer(TCPServer):
            async def handle_stream(self, stream, address):
                stream.write(b'data')
                stream.close()
        """)

        sock, port = bind_unused_port()
        server = namespace['TestServer']()
        server.add_socket(sock)
        client = IOStream(socket.socket())
        yield client.connect(('localhost', port))
        result = yield client.read_until_close()
        self.assertEqual(result, b'data')
        server.stop()
        client.close() 
開發者ID:tp4a,項目名稱:teleport,代碼行數:21,代碼來源:tcpserver_test.py

示例9: test_advanced

# 需要導入模塊: from tornado import tcpserver [as 別名]
# 或者: from tornado.tcpserver import TCPServer [as 別名]
def test_advanced(self):
        code = textwrap.dedent("""
            from __future__ import print_function
            from tornado.ioloop import IOLoop
            from tornado.netutil import bind_sockets
            from tornado.process import fork_processes, task_id
            from tornado.ioloop import IOLoop
            from tornado.tcpserver import TCPServer

            sockets = bind_sockets(0, address='127.0.0.1')
            fork_processes(3)
            server = TCPServer()
            server.add_sockets(sockets)
            IOLoop.current().run_sync(lambda: None)
            print(task_id(), end='')
        """)
        out = self.run_subproc(code)
        self.assertEqual(''.join(sorted(out)), "012") 
開發者ID:tp4a,項目名稱:teleport,代碼行數:20,代碼來源:tcpserver_test.py

示例10: test_wait_for_handshake_callback

# 需要導入模塊: from tornado import tcpserver [as 別名]
# 或者: from tornado.tcpserver import TCPServer [as 別名]
def test_wait_for_handshake_callback(self):
        test = self
        handshake_future = Future()

        class TestServer(TCPServer):
            def handle_stream(self, stream, address):
                # The handshake has not yet completed.
                test.assertIsNone(stream.socket.cipher())
                self.stream = stream
                with ignore_deprecation():
                    stream.wait_for_handshake(self.handshake_done)

            def handshake_done(self):
                # Now the handshake is done and ssl information is available.
                test.assertIsNotNone(self.stream.socket.cipher())
                handshake_future.set_result(None)

        yield self.connect_to_server(TestServer)
        yield handshake_future 
開發者ID:tp4a,項目名稱:teleport,代碼行數:21,代碼來源:iostream_test.py

示例11: test_handle_stream_coroutine_logging

# 需要導入模塊: from tornado import tcpserver [as 別名]
# 或者: from tornado.tcpserver import TCPServer [as 別名]
def test_handle_stream_coroutine_logging(self):
        # handle_stream may be a coroutine and any exception in its
        # Future will be logged.
        class TestServer(TCPServer):
            @gen.coroutine
            def handle_stream(self, stream, address):
                yield gen.moment
                stream.close()
                1 / 0

        server = client = None
        try:
            sock, port = bind_unused_port()
            with NullContext():
                server = TestServer()
                server.add_socket(sock)
            client = IOStream(socket.socket())
            with ExpectLog(app_log, "Exception in callback"):
                yield client.connect(('localhost', port))
                yield client.read_until_close()
                yield gen.moment
        finally:
            if server is not None:
                server.stop()
            if client is not None:
                client.close() 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:28,代碼來源:tcpserver_test.py

示例12: test_wait_for_handshake_already_waiting_error

# 需要導入模塊: from tornado import tcpserver [as 別名]
# 或者: from tornado.tcpserver import TCPServer [as 別名]
def test_wait_for_handshake_already_waiting_error(self):
        test = self
        handshake_future = Future()

        class TestServer(TCPServer):
            def handle_stream(self, stream, address):
                stream.wait_for_handshake(self.handshake_done)
                test.assertRaises(RuntimeError, stream.wait_for_handshake)

            def handshake_done(self):
                handshake_future.set_result(None)

        yield self.connect_to_server(TestServer)
        yield handshake_future 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:16,代碼來源:iostream_test.py

示例13: test_handle_stream_coroutine_logging

# 需要導入模塊: from tornado import tcpserver [as 別名]
# 或者: from tornado.tcpserver import TCPServer [as 別名]
def test_handle_stream_coroutine_logging(self):
        # handle_stream may be a coroutine and any exception in its
        # Future will be logged.
        class TestServer(TCPServer):
            @gen.coroutine
            def handle_stream(self, stream, address):
                yield stream.read_bytes(len(b"hello"))
                stream.close()
                1 / 0

        server = client = None
        try:
            sock, port = bind_unused_port()
            server = TestServer()
            server.add_socket(sock)
            client = IOStream(socket.socket())
            with ExpectLog(app_log, "Exception in callback"):
                yield client.connect(("localhost", port))
                yield client.write(b"hello")
                yield client.read_until_close()
                yield gen.moment
        finally:
            if server is not None:
                server.stop()
            if client is not None:
                client.close() 
開發者ID:opendevops-cn,項目名稱:opendevops,代碼行數:28,代碼來源:tcpserver_test.py

示例14: test_stop_twice

# 需要導入模塊: from tornado import tcpserver [as 別名]
# 或者: from tornado.tcpserver import TCPServer [as 別名]
def test_stop_twice(self):
        sock, port = bind_unused_port()
        server = TCPServer()
        server.add_socket(sock)
        server.stop()
        server.stop() 
開發者ID:opendevops-cn,項目名稱:opendevops,代碼行數:8,代碼來源:tcpserver_test.py


注:本文中的tornado.tcpserver.TCPServer方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。