Allow multiple messages by taking user input
This commit is contained in:
parent
fbdf2a6ef1
commit
ee4bb1a184
16
client.py
16
client.py
|
@ -28,13 +28,17 @@ def main():
|
||||||
if s is None:
|
if s is None:
|
||||||
print('could not open socket')
|
print('could not open socket')
|
||||||
sys.exit(1)
|
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:
|
with s:
|
||||||
s.sendall(b'Hello, world')
|
s.sendall(b'Hello there')
|
||||||
data = s.recv(1024)
|
try:
|
||||||
print('Received', repr(data))
|
while True:
|
||||||
|
data = s.recv(1024)
|
||||||
if __name__ == "__main__":
|
print(">: ", repr(data))
|
||||||
main()
|
response = input("$: ")
|
||||||
|
s.sendall(response.encode("UTF-8"))
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
print("Exiting.")
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
Loading…
Reference in New Issue