-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Closed as not planned
Labels
Stalebugneeds-infoIssue is lacking sufficient information and will be closed if not providedIssue is lacking sufficient information and will be closed if not provided
Description
How send "WebSocket Connection Close[FIN]"???
my server code:
from aiohttp import web
async def handle(request):
name = request.match_info.get('name', "Anonymous")
text = "Hello, " + name
return web.Response(text=text)
async def wshandle(request):
ws = web.WebSocketResponse()
await ws.prepare(request)
async for msg in ws:
print(msg.type)
if msg.type == web.WSMsgType.text:
await ws.send_str("Hello, {}".format(msg.data))
elif msg.type == web.WSMsgType.binary:
await ws.send_bytes(msg.data)
elif msg.type in (web.WSMsgType.close, web.WSMsgType.closing, web.WSMsgType.closed):
break
return ws
app = web.Application(debug=True)
app.add_routes([web.get('/echo', wshandle)])
web.run_app(app, port=8090)
my client code:
import aiohttp
import asyncio
async def main():
async with aiohttp.ClientSession() as session:
async with session.ws_connect('http://127.0.0.1:8090/echo') as ws:
await ws.send_str("Zhangsan")
# await ws.close()
loop = asyncio.get_event_loop()
loop.run_until_complete(main())
loop.close()
Metadata
Metadata
Assignees
Labels
Stalebugneeds-infoIssue is lacking sufficient information and will be closed if not providedIssue is lacking sufficient information and will be closed if not provided