Merge remote-tracking branch 'refs/remotes/origin/main'
This commit is contained in:
commit
878c444c9a
12
client.py
12
client.py
@ -16,13 +16,18 @@ def make_payload(name, msg):
|
|||||||
return json.dumps(payload).encode("utf-8")
|
return json.dumps(payload).encode("utf-8")
|
||||||
|
|
||||||
def read_msg(s):
|
def read_msg(s):
|
||||||
|
global run
|
||||||
while run:
|
while run:
|
||||||
ready_to_read, _, _ = select.select([s], [], [], 1.0)
|
ready_to_read, _, _ = select.select([s], [], [], 1.0)
|
||||||
if ready_to_read:
|
if ready_to_read:
|
||||||
data = s.recv(1024)
|
data = s.recv(1024)
|
||||||
|
if data:
|
||||||
msg = json.loads(data.decode("utf-8"))
|
msg = json.loads(data.decode("utf-8"))
|
||||||
print(f"{msg["name"]} {datetime.datetime.fromtimestamp(float(msg["time"])).strftime("%d-%m-%Y %H:%M")}")
|
print(f"{msg["name"]} {datetime.datetime.fromtimestamp(float(msg["time"])).strftime("%d-%m-%Y %H:%M")}")
|
||||||
print(msg["msg"])
|
print(msg["msg"])
|
||||||
|
else:
|
||||||
|
print("Server disconnected")
|
||||||
|
run = False
|
||||||
# print(f"Received {data!r}")
|
# print(f"Received {data!r}")
|
||||||
|
|
||||||
def event_handel(name, s):
|
def event_handel(name, s):
|
||||||
@ -32,15 +37,14 @@ def event_handel(name, s):
|
|||||||
if msg in ["", " "]:
|
if msg in ["", " "]:
|
||||||
run = False
|
run = False
|
||||||
print("Closing socket and exit")
|
print("Closing socket and exit")
|
||||||
|
elif run:
|
||||||
else:
|
|
||||||
payload = make_payload(name, msg)
|
payload = make_payload(name, msg)
|
||||||
s.sendall(payload)
|
s.sendall(payload)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
try:
|
try:
|
||||||
Host = input("Enter ip: (default 127.0.0.1) ")
|
HOST = input("Enter ip: (default 127.0.0.1) ")
|
||||||
if Host == "":
|
if HOST == "":
|
||||||
HOST = "127.0.0.1"
|
HOST = "127.0.0.1"
|
||||||
PORT_str = input("Enter port: (default 65432) ")
|
PORT_str = input("Enter port: (default 65432) ")
|
||||||
if PORT_str == "":
|
if PORT_str == "":
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user