Allow multiple messages by taking user input

This commit is contained in:
Eli Ribble 2024-08-01 14:38:24 -07:00
parent fbdf2a6ef1
commit ee4bb1a184
1 changed files with 10 additions and 6 deletions

View File

@ -28,13 +28,17 @@ def main():
if s is None:
print('could not open socket')
sys.exit(1)
print("Entering back-and-forth. You'll get to enter a new message once a message is received. Send SIGINT (use Control-C) to exit")
with s:
s.sendall(b'Hello, world')
data = s.recv(1024)
print('Received', repr(data))
if __name__ == "__main__":
main()
s.sendall(b'Hello there')
try:
while True:
data = s.recv(1024)
print(">: ", repr(data))
response = input("$: ")
s.sendall(response.encode("UTF-8"))
except KeyboardInterrupt:
print("Exiting.")
if __name__ == "__main__":
main()