I have a client and a server in python, my server is consistently sending the time to my client. My client then prints the time received, the length of the message, and that the full message was received. I know how to incorporate a basic GUI, but when I do the flow of data stops exactly where the GUI was placed. I need the GUI to display the time as it receives it, constantly updating. This is my first python project so I'm sure I'm missing something.
I'm honestly unsure of how to go about this. Any ideas are helpful.
This Is my server
import socket
import time
HEADERSIZE = 10
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((socket.gethostname(), 1243))
s.listen(5)
while True:
# now our endpoint knows about the OTHER endpoint.
clientsocket, address = s.accept()
print(f"Connection from {address} has been established.")
msg = "Welcome to the server!"
msg = f"{len(msg):<{HEADERSIZE}}"+msg
clientsocket.send(bytes(msg,"utf-8"))
while True:
time.sleep(3)
msg = f"The time is {time.time()}"
msg = f"{len(msg):<{HEADERSIZE}}"+msg
print(msg)
clientsocket.send(bytes(msg,"utf-8"))
This is my client
import socket
HEADERSIZE = 10
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((socket.gethostname(), 1243))
while True:
full_msg = ''
new_msg = True
while True:
msg = s.recv(60)
if new_msg:
print("new msg len:",msg[:HEADERSIZE])
msglen = int(msg[:HEADERSIZE])
new_msg = False
print(f"full message length: {msglen}")
full_msg += msg.decode("utf-8")
print(len(full_msg))
if len(full_msg)-HEADERSIZE == msglen:
print("full msg recvd")
print(full_msg[HEADERSIZE:])
new_msg = True
full_msg = ''
This is what the server results:
Connection from ('169.254.91.3', 64486) has been established.
29 The time is 1563997982.918763
30 The time is 1563997985.9197025
0 The time is 1563997988.9197063
This is what the client results:
new msg len: b'22 ' full message length: 22
32
full msg recvd
Welcome to the server!
new msg len: b'29 ' full message length: 29
39
full msg recvd
The time is 1563997982.918763
new msg len: b'30 ' full message length: 30
40
full msg recvd
The time is 1563997985.9197025
new msg len: b'30 ' full message length: 30
40
full msg recvd
The time is 1563997988.9197063