yea
This commit is contained in:
parent
e4117b60ef
commit
5d9fc420ad
25
.vscode/settings.json
vendored
25
.vscode/settings.json
vendored
@ -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"
|
||||
}
|
||||
}
|
Binary file not shown.
BIN
build/src/main.o
BIN
build/src/main.o
Binary file not shown.
18
test.py
18
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 <server_ip> <server_port>")
|
||||
|
Loading…
Reference in New Issue
Block a user