Files
multithreaded-tcp-server-demo/client.py
2023-08-11 09:32:11 +02:00

34 lines
566 B
Python

import socket
import uuid
HOST = "127.0.0.1"
PORT = 10000
def main():
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((HOST, PORT))
n = 0
client_uuid = uuid.uuid4()
try:
while True:
message = f"[{client_uuid}] Hello world from client: {n}"
sock.send(message.encode("ascii"))
rx_data = sock.recv(1024)
print(f"RX: {rx_data.decode('ascii')}")
n += 1
except ConnectionError:
pass
sock.close()
if __name__ == "__main__":
main()