aboutsummaryrefslogtreecommitdiff
path: root/voctogui/lib/connection.py
diff options
context:
space:
mode:
authorMarkus Otto <otto@fs.tum.de>2015-08-22 19:15:22 +0200
committerMaZderMind <git@mazdermind.de>2015-08-31 20:02:04 +0200
commit46aace37db5c035a6d6b432db261dc7c417456f4 (patch)
treecc98a569c8c02491ce59cbf5b9a5613c96fd78b2 /voctogui/lib/connection.py
parent5c243f1cac5cc489f3bbb821ab5064d9edf7d449 (diff)
make protocol work, some gui stuff
Diffstat (limited to 'voctogui/lib/connection.py')
-rw-r--r--voctogui/lib/connection.py33
1 files changed, 32 insertions, 1 deletions
diff --git a/voctogui/lib/connection.py b/voctogui/lib/connection.py
index 37851f0..ac7243d 100644
--- a/voctogui/lib/connection.py
+++ b/voctogui/lib/connection.py
@@ -10,6 +10,37 @@ def establish(host):
log.info('establishing Connection to %s', host)
sock = socket.create_connection( (host, port) )
log.debug('Connection successful \o/')
+ # TODO: register IO callback here
-def ask(command):
+
+def send(command):
print("would send command talk to server now and read back the response")
+ filelike = sock.makefile('rw')
+ filelike.write(command + "\n")
+ filelike.flush()
+
+
+def on_data(args*):
+ filelike = sock.makefile()
+ line = ''
+ try:
+ line = filelike.readline()
+ except Exception as e:
+ log.warn("Can't read from socket: %s", e)
+
+ if len(line) == 0:
+ close_connection()
+ return False
+
+ line = line.strip()
+
+ process_line(line)
+
+
+def process_line(line):
+ msg_type = line.split()[0]
+
+
+def close_connection():
+ pass
+