其目的是让多个客户机连接到服务器,并在它们仍然连接时向它们发送数据包。一对一通信没有任何问题,也没有断管问题,当我们有多个客户机连接到服务器时,问题就出现了。在import socket
import os
import time
bind_ip = '192.168.4.4'
bind_port = 12345
payload = []
devices = []
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)
server.bind((bind_ip, bind_port))
server.listen(5) # max backlog of connections
print 'Listening on {}:{}'.format(bind_ip, bind_port)
def send(counts, payload):
x = counts #No of iterations.
y = 0
start_time = time.time()
while(x != 0):
try:
client_socket, address = server.accept()
devices.append(client_socket)
except socket.error:
break
print client_socket
print 'A