- 授权协议: Apache
- 开发语言: Python
- 操作系统: 跨平台
- 软件首页: https://github.com/KeepSafe/aiohttp
- 软件文档: https://aiohttp.readthedocs.org/en/stable/
软件介绍
aiohttp 是 asyncio 的 HTTP 客户端/服务端 (PEP 3156)。
特性
Web-server 有中间件和可插拔路由
服务器端简单使用示例:
import asyncio from aiohttp import web @asyncio.coroutine def handle(request): name = request.match_info.get('name', "Anonymous") text = "Hello, " + name return web.Response(body=text.encode('utf-8')) @asyncio.coroutine def wshandler(request): ws = web.WebSocketResponse() ws.start(request) while True: msg = yield from ws.receive() if msg.tp == web.MsgType.text: ws.send_str("Hello, {}".format(msg.data)) elif msg.tp == web.MsgType.binary: ws.send_bytes(msg.data) elif msg.tp == web.MsgType.close: break return ws @asyncio.coroutine def init(loop): app = web.Application(loop=loop) app.router.add_route('GET', '/echo', wshandler) app.router.add_route('GET', '/{name}', handle) srv = yield from loop.create_server(app.make_handler(), '127.0.0.1', 8080) print("Server started at http://127.0.0.1:8080") return srv loop = asyncio.get_event_loop() loop.run_until_complete(init(loop)) loop.run_forever()
为你推荐:
Linux多线程服务端编程
陈硕 / 电子工业出版社 / 2013-1-15 / 89.00元
本书主要讲述采用现代C++ 在x86-64 Linux 上编写多线程TCP 网络服务程序的主流常规技术,重点讲解一种适应性较强的多线程服务器的编程模型,即one loop per thread。这是在Linux 下以native 语言编写用户态高性能网络程序最成熟的模式,掌握之后可顺利地开发各类常见的服务端网络应用程序。本书以muduo 网络库为例,讲解这种编程模型的使用方法及注意事项。 本......一起来看看 《Linux多线程服务端编程》 这本书的介绍吧!