-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
28 lines (23 loc) · 1.32 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import time
from clients.receiver import Receiver
from clients.sender import Sender
while True:
msg = input("Client (1) Server (2) End of program (3): ")
if msg == "3":
break
if msg == "1": # If input is '1', initiate as a Sender
user = Sender()
elif msg == "2": # If input is '2', initiate as a Receiver
user = Receiver()
else:
print("Wrong input")
continue
switch_status = user.request() if msg == "1" else user.listen() # Perform initial action based on user input
while switch_status is not None:
if msg == "1": # If previous input was Sender
user = Receiver(switch_status) # Create a Receiver object with the received status
else:
time.sleep(5) # If previous input was Receiver
user = Sender(switch_status) # Create a Sender object with the received status
switch_status = user.listen() if msg == "1" else user.request() # Update the switch_status based on the action taken by the user
msg = "2" if msg == "1" else "1" # Switch the message between Client and Server