netpong/scripts/client.py
Christoph J. Scherr b0fb7de6e9
All checks were successful
cargo devel CI / cargo CI (push) Successful in 2m29s
concurrency
2024-01-23 13:50:40 +01:00

26 lines
553 B
Python

import socket
def ping():
HOST = "127.0.0.1"
PORT = 9999
payload = b"ping\0"
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.connect((HOST, PORT))
while True:
try:
s.sendall(payload)
print("> ping")
except Exception as e:
break
reply = s.recv(1024).decode()
if reply == "":
break
print(f"< {reply}")
print("connection shut down")
if __name__ == "__main__":
ping()