VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > Python基础教程 >
  • Python3标准库:selectors I/O多路复用抽象(2)

ready to read')
  • data = connection.recv(1024)
  • if data:
  • # A readable client socket has data
  • print(' received {!r}'.format(data))
  • bytes_received += len(data)
  •  
  • # Interpret empty result as closed connection,
  • # and also close when we have received a copy
  • # of all of the data sent.
  • keep_running = not (
  • data or
  • (bytes_received and
  • (bytes_received == bytes_sent))
  • )
  •  
  • if mask & selectors.EVENT_WRITE:
  • print(' ready to write')
  • if not outgoing:
  • # We are out of messages, so we no longer need to
  • # write anything. Change our registration to let
  • # us keep reading responses from the server.
  • print(' switching to read-only')
  • mysel.modify(sock, selectors.EVENT_READ)
  • else:
  • # Send the next message.
  • next_msg = outgoing.pop()
  • print(' sending {!r}'.format(next_msg))
  • sock.sendall(next_msg)
  • bytes_sent += len(next_msg)
  •  
  • print('shutting down')
  • mysel.unregister(connection)
  • connection.close()
  • mysel.close()
  • 这个客户不仅跟踪它发出的数据量,还会跟踪接收的数据量。当这些值一致而且非0时,客户退出处理循环,并妥善地关闭,它将从选择器删除套接字,并关闭套接字和选择器。

    1.4 服务器和客户

    要在不同的终端窗口运行客户和服务器,使它们能够相互通信。服务器输出显示了入站连接和数据,以及发回给客户的响应。

    客户输入显示了发出的信息和从服务器得到的响应。

    
    相关教程
    关于我们--广告服务--免责声明--本站帮助-友情链接--版权声明--联系我们       黑ICP备07002182号