diff --git a/.vscode/settings.json b/.vscode/settings.json index ffe9ada..c50b5d4 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -3,6 +3,7 @@ "*.pyx": "python", "*.js": "javascript", "*.c": "c", + "*.scene": "yaml", "array": "cpp", "atomic": "cpp", "bit": "cpp", @@ -67,6 +68,28 @@ "thread": "cpp", "cinttypes": "cpp", "typeinfo": "cpp", - "variant": "cpp" + "variant": "cpp", + "xstring": "cpp", + "ios": "cpp", + "list": "cpp", + "locale": "cpp", + "map": "cpp", + "queue": "cpp", + "shared_mutex": "cpp", + "xfacet": "cpp", + "xhash": "cpp", + "xiosbase": "cpp", + "xlocale": "cpp", + "xlocbuf": "cpp", + "xlocinfo": "cpp", + "xlocmes": "cpp", + "xlocmon": "cpp", + "xlocnum": "cpp", + "xloctime": "cpp", + "xmemory": "cpp", + "xtr1common": "cpp", + "xtree": "cpp", + "xutility": "cpp", + "text_encoding": "cpp" } } \ No newline at end of file diff --git a/build/src/Server.o b/build/src/Server.o index b09b3e7..0d53405 100644 Binary files a/build/src/Server.o and b/build/src/Server.o differ diff --git a/build/src/main.o b/build/src/main.o index 4ba9914..38a2b06 100644 Binary files a/build/src/main.o and b/build/src/main.o differ diff --git a/main.exe b/main.exe index 6964428..dee4b1f 100644 Binary files a/main.exe and b/main.exe differ diff --git a/test.py b/test.py index 0e09c7f..5d191cc 100644 --- a/test.py +++ b/test.py @@ -6,6 +6,7 @@ import tkinter as tk from tkinter import scrolledtext, messagebox import queue import sys +import time # Import time module for current timestamp in ms PACKET_NAMES = { 1: "HEARTBEAT", @@ -87,6 +88,7 @@ class PacketClient: if self.sock: self.sock.close() + # The GUI application. class PacketClientGUI: def __init__(self, master, client: PacketClient): @@ -120,6 +122,21 @@ class PacketClientGUI: def process_recv_queue(self): while not self.client.recv_queue.empty(): pkt_type, data = self.client.recv_queue.get() + # For heartbeat packets (type 1), calculate ping and update window title. + if pkt_type == 1: + try: + serverTimestamp = int(data) + msNow = int(time.time() * 1000) + ping = msNow - serverTimestamp + self.master.title(f"Heartbeat: {ping} ms") + except Exception as e: + # If there's an error parsing the timestamp, show the error in the log. + self.append_text(f"Error processing HEARTBEAT: {e}\n") + continue + # For ping packets (type 10), update the window title using the packet data. + if pkt_type == 10: + self.master.title(data) + continue if isinstance(pkt_type, int): name = PACKET_NAMES.get(pkt_type, f"Unknown ({pkt_type})") else: @@ -148,6 +165,7 @@ class PacketClientGUI: except Exception as e: tk.messagebox.showerror("Error", str(e)) + def main(): if len(sys.argv) < 3: print("Usage: python packet_client_gui.py ")