-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisplay_terra.py
58 lines (43 loc) · 1.04 KB
/
display_terra.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
import socket
import os
import simplejson as json
from utils import eprint
server_address = '/var/run/rendezvous/terra/display'
try:
os.unlink(server_address)
except OSError:
if os.path.exists(server_address):
raise
sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
eprint("starting up on ", server_address)
sock.bind(server_address)
sock.listen(1)
def do_command(command):
return 0
while True:
eprint("waiting for connection")
connection, client_address = sock.accept()
try:
eprint("connection from:", client_address)
#while True:
data = connection.recv(100)
#eprint("received", data)
command = json.loads(data)
print command["command"]
print command["text"]
print "procesing the command"
response = do_command(command)
if response == 0:
print "done!"
data = json.dumps({"response":"ok"})
connection.sendall(data)
"""
if data:
eprint("sending back to the client")
connection.sendall(data)
else:
eprint("no more data from", client_address)
break
"""
finally:
connection.close()