For a friend.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

client.py 672B

12345678910111213141516171819202122232425262728293031
  1. #!/usr/bin/env python3
  2. import socket
  3. from cmd import Cmd
  4. TCP_IP = '127.0.0.1'
  5. TCP_PORT = 5005
  6. BUFFER_SIZE = 1024
  7. MESSAGE = b"Hello, World!"
  8. s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  9. s.connect((TCP_IP, TCP_PORT))
  10. class MyPrompt(Cmd):
  11. def do_exit(self, inp):
  12. '''exit the application and close remote server.'''
  13. s.send(b"exit")
  14. data = s.recv(BUFFER_SIZE)
  15. print ("received data:", data)
  16. return True
  17. def do_send(self, inp):
  18. '''Send a message'''
  19. s.send(bytes(inp, "utf8"))
  20. print(inp)
  21. data = s.recv(BUFFER_SIZE)
  22. print ("received data:", data)
  23. MyPrompt().cmdloop()
  24. s.close()