我想问一下如何跳过接收功能。
def client():
try:
b = bytes.decode(h.recv(1024))
print("The recieved message : ",b)
b1 = str.encode(b)
c.sendall(b1)
h.sendall(b1)
y.sendall(b1)
except Exception:
pass
try:
g = bytes.decode(y.recv(1024))
print("The recieved message : ",g)
g1 = str.encode(g)
c.sendall(g1)
h.sendall(g1)
y.sendall(g1)
except Exception:
pass
所以我需要做的是检查是否有来自客户端的消息:
答案 0 :(得分:0)
您需要轮询机制。最简单的是select
import select
def client():
sockets, _, _ = select.select([h, y], [], [])
# If h or y has data, select exits and returns these sockets
for sock in sockets:
try:
data = sock.recv(1024)
if data == '':
# sock was disconnected handle that
continue
# Process data here
except Exception:
continue