我希望能够将数据包发送到连接到套接字对象(服务器端)的所有设备。
下面是我想要实现的目标(服务器端)的示例:
import socket
def server(s): # s is the socket object
while True:
c, addr = s.accept()
msg = c.recv(4096).decode()
# some way of sending what is received to all hosts connected?
假设
c
是您的客户,只需c.sendall(bytes(msg))