这是我的服务器代码:
import sys, time, socket, threading, random
def newClient(c):
global data
c.send("Connected to stream".encode())
while True:
c.sendall(str(data).encode())
time.sleep(10)
def setData():
data = random.random()
return data
def readData():
global data
while True:
data = setData()
port = 12312
ssock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
ssock.bind(('', port))
ssock.listen(5)
data = random.random()
threading.Thread(target=readData).start()
while True:
c, addr = ssock.accept()
print("[-] Connected to " + addr[0] + ":" + str(addr[1]))
threading.Thread(target=newClient, args=(c,)).start()
如果有人能指出我正确的方向,以便我的服务器向两个客户发送相同的数据,我将非常感激。