擅长:python、mysql、java
<p>请等待服务器关闭连接,或使用<code>transport.close()</code>关闭传输。这也将触发<code>connection_lost</code>(不要从<code>connection_lost</code>调用<code>transport.close()</code>!)公司名称:</p>
<pre><code>class ClientConnection(asyncio.Protocol):
def connection_made(self, transport):
logging.debug("connection made, calling write eof")
transport.write_eof()
logging.debug("after calling write eof, calling close")
transport.close()
logging.debug("after calling close")
def connection_lost(self, exception):
logging.debug("connection lost")
super().connection_lost(exception)
</code></pre>
<p>如果您再尝试一点,您可能还会为您的本地计算机获得一些<code>ResourceWarning</code>。例如,尝试在<code>write_eof()</code>之前添加<code>transport.write(b'hello world!')</code>,或者使本地服务器响应较慢。在</p>