The final line in parse_message(line)
reads:
{... }.get(toks[0], inv)()
I think it should be
{... }.get(toks[0])()
EDIT
I can successfully send an IAMAT message and have it parsed by the server:
nc -c localhost 12604
IAMAT b 1 2 3
AT Young 1394489423.5 b 1.0 2.0 3.0
But I'm a little confused as to what should happen next. The server seems to attempt to establish new connections back to itself using TCP4ClientEndpoint (rather than using the existing connections to the clients) in order to send AT messages. There seems to be a problem here where the messages aren't sent, but if this succeeded, wouldn't it result in a continuous loop of messages going back and forth within the server?
EDIT 2
Thanks for the clarification. By default, Twisted's LineReceiver expects lines to be terminated by a carriage return and new line character (\r\n
). Your messages are being sent, but then subsequently ignored as your flatten_cmd
function only appends \n
. Changing it to the following fixes this problem:
def flatten_cmd(schema, cmd):
ret = cmd['type']
for x in schema:
k = x[0]
ret = ret + ' ' + str(cmd[k])
return ret+'\r\n'
And now the server receives the updates as expected:
got IAMAT blah 1 2 3
sending AT Farmar 1394676270.11 blah 1.0 2.0 3.0
sending AT Farmar 1394676270.11 blah 1.0 2.0 3.0
got AT Farmar 1394676270.11 blah 1.0 2.0 3.0
got AT Farmar 1394676270.11 blah 1.0 2.0 3.0