<kbd id="afajh"><form id="afajh"></form></kbd>
<strong id="afajh"><dl id="afajh"></dl></strong>
    <del id="afajh"><form id="afajh"></form></del>
        1. <th id="afajh"><progress id="afajh"></progress></th>
          <b id="afajh"><abbr id="afajh"></abbr></b>
          <th id="afajh"><progress id="afajh"></progress></th>

          aiohttpasyncio 的 HTTP 客戶端/服務(wù)端

          聯(lián)合創(chuàng)作 · 2023-09-29 08:19

          aiohttp 是 asyncio 的 HTTP 客戶端/服務(wù)端。

          特性

          服務(wù)器端簡單使用示例:

          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()
          瀏覽 16
          點(diǎn)贊
          評論
          收藏
          分享

          手機(jī)掃一掃分享

          編輯 分享
          舉報
          評論
          圖片
          表情
          推薦
          點(diǎn)贊
          評論
          收藏
          分享

          手機(jī)掃一掃分享

          編輯 分享
          舉報
          <kbd id="afajh"><form id="afajh"></form></kbd>
          <strong id="afajh"><dl id="afajh"></dl></strong>
            <del id="afajh"><form id="afajh"></form></del>
                1. <th id="afajh"><progress id="afajh"></progress></th>
                  <b id="afajh"><abbr id="afajh"></abbr></b>
                  <th id="afajh"><progress id="afajh"></progress></th>
                  黄色大全在线观看 | 日韩午夜福利在线观看 | 无码流出在线观看 | 可以看的黄色网址 | 成人三级小视频 |