我正在使用此代码尝试使用aiohttp来运行服务器套接字,但是每当我启动脚本Server Started
时,都不会输出到命令行
async def socket_server(reader, writer):
print("Server Started")
data = await reader.read(100)
message = data.decode()
addr = writer.get_extra_info('peername')
print("Received %r from %r" % (message, addr))
print("Send: %r" % message)
writer.write(data)
await writer.drain()
print("Close the client socket")
writer.close()
loop = asyncio.get_event_loop()
coro = asyncio.start_server(socket_server, '127.0.0.1', 9000, loop=loop)
server = loop.run_until_complete(coro)
try:
loop.run_forever()
except KeyboardInterrupt:
pass
server.close()
loop.run_until_complete(server.wait_closed())
loop.close()