Cleanup
This commit is contained in:
parent
a00c6822ce
commit
5040464aab
@ -14,19 +14,25 @@ from Thing import Thing
|
||||
class Participant:
|
||||
publishInterval = 3000 # 3 seconds
|
||||
|
||||
buffer = bytearray(256)
|
||||
network_id = 0
|
||||
nextPublishMe = 0
|
||||
others = []
|
||||
thread = None
|
||||
|
||||
def __init__(self, ipAddress = "0.0.0.0", port=7681, remote=False):
|
||||
self.buffer = bytearray(256)
|
||||
# self.buffer = bytearray(256)
|
||||
self.ip_address = ipAddress
|
||||
self.port = port
|
||||
self.udp_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
|
||||
self.udp_socket.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
|
||||
self.buffer = bytearray(256)
|
||||
# self.buffer = bytearray(256)
|
||||
|
||||
if remote == False:
|
||||
self.udp_socket.bind(("0.0.0.0", 7681))
|
||||
self.network_id = 0
|
||||
self.nextPublishMe = 0
|
||||
self.others = []
|
||||
# self.network_id = 0
|
||||
# self.nextPublishMe = 0
|
||||
# self.others = []
|
||||
self.AddParticipant(self.ip_address, self.port)
|
||||
|
||||
self.thread = threading.Thread(target = self.Receiver)
|
||||
@ -45,13 +51,13 @@ class Participant:
|
||||
self.others.append(remote_participant)
|
||||
return remote_participant
|
||||
|
||||
def Update(self, currentTime):
|
||||
if (currentTime > self.nextPublishMe):
|
||||
def Update(self, currentTimeMs):
|
||||
if (currentTimeMs > self.nextPublishMe):
|
||||
self.Publish(ClientMsg(self.network_id))
|
||||
print(f'Sent ClientMsg {self.network_id}')
|
||||
self.nextPublishMe = currentTime + Participant.publishInterval
|
||||
self.nextPublishMe = currentTimeMs + Participant.publishInterval
|
||||
|
||||
Thing.UpdateAll(currentTime)
|
||||
Thing.UpdateAll(currentTimeMs)
|
||||
|
||||
#region Send
|
||||
|
||||
|
@ -8,11 +8,8 @@ class ThingTest(unittest.TestCase):
|
||||
|
||||
def test_client_msg(self):
|
||||
participant: Participant = Participant(ipAddress="127.0.0.1", port=7681)
|
||||
thing: Thing = Thing()
|
||||
milliseconds = time.time() * 1000
|
||||
|
||||
thing.update(milliseconds)
|
||||
Thing.UpdateAll(milliseconds)
|
||||
start_time = milliseconds
|
||||
while milliseconds < start_time + 5000:
|
||||
milliseconds = time.time() * 1000
|
||||
|
Loading…
x
Reference in New Issue
Block a user