我的服务器可以正常使用我的选择功能:
readable, writable, exceptional = select.select(inputs, outputs, timeout)
这是可写循环的代码:
for s in writable:
try:
next_msg = message_queues[s].get_nowait()
except Queue.Empty:
# No messages waiting so stop checking for writability.
print >>sys.stderr, 'output queue for', s.getpeername(), 'is empty'
outputs.remove(s)
else:
print >>sys.stderr, 'sending "%s" to %s' % (next_msg, s.getpeername())
s.send(next_msg)
s 是套接字对象。这里的代码只发送给发送东西的客户。我只想将 next_msg 多播到彼此的可写套接字,所以我尝试了:
for s in writable:
try:
next_msg = message_queues[s].get_nowait()
except Queue.Empty:
# No messages waiting so stop checking for writability.
print >>sys.stderr, 'output queue for', s.getpeername(), 'is empty'
outputs.remove(s)
else:
for multicast in writable:
print >>sys.stderr, 'sending "%s" to %s' % (next_msg, multicast.getpeername())
multicast.send(next_msg)
但这不起作用,它总是只发送给发件人。