当前位置: 首页>>代码示例>>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;未经允许,请勿转载。