-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathg_client.py
43 lines (31 loc) · 888 Bytes
/
g_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
import gevent
from gevent import monkey
monkey.patch_socket()
import cmd
addr = ('localhost', 6001)
def send_cmd(command):
socket = gevent.socket.socket()
socket.connect(addr)
socket.send(command+'\n')
print socket.recv(1024)
socket.close()
class ClientCmd(cmd.Cmd):
"""Simple command processor example."""
def do_status(self, line):
send_cmd('status')
def do_stop(self, line):
if not line:
print 'Please give the process name'
else:
send_cmd('stop '+line)
def do_start(self, line):
if not line:
print 'Please give the process name'
else:
send_cmd('start '+line)
def do_shutdown(self, line):
send_cmd('shutdown '+line)
def do_EOF(self, line):
return True
if __name__ == '__main__':
ClientCmd().cmdloop()