Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- import sys
- import socket
- import time
- from datetime import timedelta, datetime
- def main():
- UDP_PORT = 8888
- sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
- sock.bind(("", UDP_PORT))
- last = datetime.now()
- missed = 0
- while True:
- data, addr = sock.recvfrom(4096)
- now = datetime.now()
- secs = int(data.decode("utf-8"))*20
- uptime = timedelta(seconds=secs)
- if (now-last).total_seconds() >= 30.0:
- missed+=1
- print("uptime:", uptime, "missed packets:", missed)
- last = now
- sys.stdout.flush()
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement