aboutsummaryrefslogtreecommitdiff
path: root/inputs/TCPInput.py
diff options
context:
space:
mode:
Diffstat (limited to 'inputs/TCPInput.py')
-rw-r--r--inputs/TCPInput.py15
1 files changed, 7 insertions, 8 deletions
diff --git a/inputs/TCPInput.py b/inputs/TCPInput.py
index 513b853..17ea7e6 100644
--- a/inputs/TCPInput.py
+++ b/inputs/TCPInput.py
@@ -6,6 +6,10 @@ import logging as main_log
import string
class TCPInput(Input):
+ """TCPInput is a input to receive input on a TCP port. In its current incarnation, it parses
+ json data into python dicts. Warning: contains a bug where init will hang until it receives a
+ connection. Specify:
+ <Port> -- Port number to listen on."""
def inputInit(self):
self.HOST = '' # Symbolic name meaning all available interfaces
self.PORT = self.argDict['Port'] # Arbitrary non-privileged port
@@ -21,25 +25,20 @@ class TCPInput(Input):
def sensingLoop(self):
data = self.conn.recv(self.BUFFER_SIZE)
main_log.debug('Incoming data', data)
+
if not data or 'end' in data: # data end, close socket
main_log.debug('End in data')
print 'end of stream'
self.IS_RESPONDING = 0
self.conn.close()
self.sock.close()
-
- if self.IS_RESPONDING == 1: # if 'responding', respond to the received data
- #dataDict = json.loads(data)
+
+ if self.IS_RESPONDING == 1: # if 'responding', respond to the received data
try:
for datagroup in data.split('\n'):
if datagroup != None and datagroup != '':
dataDict = json.loads(datagroup)
- #print dataDict
self.respond(dataDict)
- #socketDict = {'data':dataDict, 'address':self.address}
- #socketDict = {Strings.LOCATION: (dataDict['x'], dataDict['y'])} # like PygameInput
- #print 'input'
- #self.respond(socketDict)
except Exception as exp:
print str(exp)
else: