This commit is contained in:
yumoqing 2020-10-29 10:51:59 +08:00
parent c31fbde37d
commit a58bb318e0

View File

@ -12,8 +12,8 @@ class BroadcastServer:
self.udpSerSock = socket(AF_INET, SOCK_DGRAM) self.udpSerSock = socket(AF_INET, SOCK_DGRAM)
# 设置阻塞 # 设置阻塞
self.udpSerSock.setblocking(1) self.udpSerSock.setblocking(1)
# 设置超时时间 0.5s # 设置超时时间 1s
# self.udpSerSock.settimeout(0.5) # self.udpSerSock.settimeout(1)
self.udpSerSock.bind(('' ,port)) self.udpSerSock.bind(('' ,port))
self.run_flg = True self.run_flg = True
self.thread = Background(self.run) self.thread = Background(self.run)
@ -40,9 +40,9 @@ def find_players(port):
host = get_free_local_addr()[0] host = get_free_local_addr()[0]
udpCliSock = socket(AF_INET, SOCK_DGRAM) udpCliSock = socket(AF_INET, SOCK_DGRAM)
#设置阻塞 #设置阻塞
udpCliSock.setblocking(2) #udpCliSock.setblocking(2)
#设置超时时间 #设置超时时间
udpCliSock.settimeout(2) udpCliSock.settimeout(0.5)
udpCliSock.bind(('', 0)) udpCliSock.bind(('', 0))
udpCliSock.setsockopt(SOL_SOCKET, SO_BROADCAST, 1) udpCliSock.setsockopt(SOL_SOCKET, SO_BROADCAST, 1)
print('find_players() port=',port) print('find_players() port=',port)