Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

fix the code if join 2 clinet its print twice if 3 its print 3 i think beacue of thread i want to clinet print

fix the code if join 2 clinet its print twice if 3 its print 3 i think beacue of thread i want to clinet print one every time sleep and not dublcate python program stored_clients = [None] * max_clients def handle_client(client_socket, address, client_number): latest_usage_info = "" lock = threading.Lock() def print_latest_usage_info(): latest_usage = {} while True: time.sleep(report_time) with lock: for i, usage_info in enumerate(stored_clients): if usage_info is not None: latest_usage[i+1] = usage_info for i in range(1, len(stored_clients)+1): if i in latest_usage: print(f"Client-{i} Usage Info:") print(latest_usage[i]) print_thread = threading.Thread(target=print_latest_usage_info) print_thread.start() while True: usage_info = client_socket.recv(1024).decode() if not usage_info: break with lock: if stored_clients[client_number-1] != usage_info: stored_clients[client_number-1] = usage_info client_socket.sendall(str(report_time).encode()) 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Principles Programming And Performance

Authors: Patrick O'Neil

1st Edition

1558603921, 978-1558603929

More Books

Students also viewed these Databases questions

Question

10-9 How have social technologies changed e-commerce?

Answered: 1 week ago