netpong/scripts/client.py

27 lines
553 B
Python
Raw Normal View History

2024-01-19 16:33:11 +01:00
import socket
2024-01-23 13:50:40 +01:00
def ping():
2024-01-19 16:33:11 +01:00
2024-01-23 13:50:40 +01:00
HOST = "127.0.0.1"
PORT = 9999
2024-01-19 16:33:11 +01:00
2024-01-23 13:50:40 +01:00
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()