如果当前客户机没有用Python发送任何数据,如何添加超时,以便移动到下一个客户机?我将所有连接的客户机都存储在conn_clients
列表中。你知道吗
下面是我的接收函数代码:
def receive(connection):
curr_con = connection
while True:
message = connection.recv(BUFFER_SIZE)
if not message:
print "Closing connection"
conn_clients.remove(connection) #removing socket from list
return
send_all(curr_con, message) #sending message to all cleints
你没有提到操作系统,我也不确定这是否适用于Windows。你知道吗
GLib提供了超时函数,您可以启动它并告诉它在某个时间间隔后执行某个函数。我找到了this article,它显示了如何将g\u io\u add\u watch连接到socket事件(比等待事件更干净)并同时启动计时器(从同一个库)。如果套接字在设置的时间内没有显示活动,则函数可以中止套接字进程。你知道吗
相关问题 更多 >
编程相关推荐