import socket
import time
HOST = '' # Symbolic name meaning all available interfaces
PORT = 7778 # Port number (non-privileged ports are > 1023),Same port as used by the server
COUNT_LIMIT = 60 # Limit of data packets to send
count = 0 # Initialize counter
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.bind((HOST, PORT))
s.listen()
conn, addr = s.accept()
with conn:
print('Connected by', addr)
while count < COUNT_LIMIT: # Loop until we reach the limit
time.sleep(0.1) # Sleep for 0.1 seconds
conn.sendall(b'1') # Send the number '1'
count += 1 # Increment counter after each send
else:
print(f'Sent {count} packets, closing connection.') # Print message when limit is reached