fix: silly rounding error on UDP stale check
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,2 +1,2 @@
|
||||
*.csv
|
||||
__pycache__
|
||||
*/**/__pycache__/
|
||||
|
||||
@@ -15,11 +15,10 @@ class UDPClient(SocketClient):
|
||||
|
||||
def Send(self, data: str):
|
||||
now = time.time()
|
||||
data = "%s/%f" % (data, now)
|
||||
data = f"{data}/{now}"
|
||||
self.socket.sendto(data.encode(), (self.ip, self.port))
|
||||
self.logger.info("UDP_SENT %s" % data)
|
||||
self._timestamps.add(now)
|
||||
print(self._timestamps)
|
||||
self.Receive()
|
||||
self.staleCheck()
|
||||
|
||||
@@ -34,7 +33,6 @@ class UDPClient(SocketClient):
|
||||
print(timestamp.decode())
|
||||
self.logger.info("UDP_SUCCESS %s (%s)" % (data.decode(), addr))
|
||||
self._timestamps.discard(float(timestamp.decode()))
|
||||
print(self._timestamps)
|
||||
|
||||
def staleCheck(self):
|
||||
if (time.time() - self._last_check) < 1:
|
||||
@@ -45,7 +43,6 @@ class UDPClient(SocketClient):
|
||||
if (self._last_check - timestamp) < 10:
|
||||
continue
|
||||
self.logger.error("UDP_FAIL %f" % timestamp)
|
||||
print(self._timestamps)
|
||||
timedout_timestamps.add(timestamp)
|
||||
|
||||
self._last_check = time.time()
|
||||
|
||||
@@ -54,7 +54,7 @@ def main():
|
||||
udp.Connect()
|
||||
|
||||
while True:
|
||||
# tcp.Send("meow")
|
||||
tcp.Send("meow")
|
||||
udp.Send("woof")
|
||||
time.sleep(9)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user