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 830B

1234567891011121314151617181920212223242526272829303132333435363738
  1. import socket
  2. def read_view(f):
  3. view = f.readline()
  4. if not view:
  5. return
  6. for x in range(2, len(view)):
  7. line = f.readline()
  8. if not line:
  9. return
  10. view += line
  11. return view
  12. def main(host, port):
  13. s = socket.socket()
  14. s.connect((host, port))
  15. f = s.makefile()
  16. commands = {'w': '^', 'a': '<', 's': 'v', 'd': '>', 'W': '^', 'A': '<', 'S': 'v', 'D': '>'}
  17. while True:
  18. try:
  19. view = read_view(f)
  20. if not view:
  21. break
  22. print(view)
  23. cmd = input("[WASD]:")
  24. cmd = commands[cmd]
  25. if cmd is None:
  26. break
  27. s.send(str.encode(cmd))
  28. except Exception as e:
  29. print(e)
  30. break
  31. s.close()
  32. port = 63188
  33. main("141.75.33.7", port)