-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.py
65 lines (58 loc) · 1.4 KB
/
client.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
from multiprocessing.connection import Client
from multiprocessing.context import AuthenticationError
import getpass
import os
import readline
import sys
MAX_RETRIES = 3
CAFF_ON = ""
CAFF_OFF = ""
fancy = not ("--ascii" in sys.argv or "-a" in sys.argv)
address = ("localhost", 6000)
tries = 0
connected = False
while tries <= MAX_RETRIES:
try:
pwd = getpass.getpass(prompt="Server Authkey: ")
conn = Client(address, authkey=bytes(pwd, "ascii"))
connected = True
break
except ConnectionRefusedError:
print("Server not running")
break
except AuthenticationError:
print("Wrong Password!")
tries += 1
else:
print("You have exceeded the number of retries. (%s)" % MAX_RETRIES)
while connected:
if fancy:
icon = CAFF_OFF
conn.send("current")
current = conn.recv()
if current == "ignore":
icon = CAFF_ON
else:
icon = ">"
print("%s " % icon, end="")
try:
cmd = input()
except KeyboardInterrupt:
print("^C")
continue
if cmd == "exit":
print("Exiting...")
connected = False
conn.send("close connection")
break
elif cmd == "clear":
os.system("clear")
continue
elif cmd == "":
print()
continue
conn.send(cmd)
try:
print(conn.recv())
except EOFError:
pass