如何使用Python套接字消息向所有连接的主机发送消息?

问题描述 投票:0回答:1

我希望能够将数据包发送到连接到套接字对象(服务器端)的所有设备。

下面是我想要实现的目标(服务器端)的示例:

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?
python python-3.x sockets network-programming
1个回答
0
投票

假设

c
是您的客户,只需
c.sendall(bytes(msg))

© www.soinside.com 2019 - 2024. All rights reserved.