1234567891011121314151617181920212223242526272829303132333435363738 |
- import socket
-
- def read_view(f):
- view = f.readline()
- if not view:
- return
- for x in range(2, len(view)):
- line = f.readline()
- if not line:
- return
- view += line
- return view
-
- def main(host, port):
- s = socket.socket()
- s.connect((host, port))
- f = s.makefile()
-
- commands = {'w': '^', 'a': '<', 's': 'v', 'd': '>', 'W': '^', 'A': '<', 'S': 'v', 'D': '>'}
-
- while True:
- try:
- view = read_view(f)
- if not view:
- break
- print(view)
- cmd = input("[WASD]:")
- cmd = commands[cmd]
- if cmd is None:
- break
- s.send(str.encode(cmd))
- except Exception as e:
- print(e)
- break
- s.close()
-
- port = 63188
- main("141.75.33.7", port)
|