diff options
author | Vadim Yanitskiy <axilirator@gmail.com> | 2018-08-09 19:30:39 +0700 |
---|---|---|
committer | Vadim Yanitskiy <axilirator@gmail.com> | 2018-08-10 16:38:59 +0700 |
commit | 0e246372bc692f2f12198b61010c4ea156056428 (patch) | |
tree | c48814ec8cf4a8c408d89689d2d7efedce0e50d4 /python/trx/udp_link.py | |
parent | b085a2c8540ea89c49c7aa9eac543405a948196a (diff) |
trx/ctrl_if.py: send control responses to where commands are from
When we receive a control command, we should not simply send the
response to the default destination, but send it back to the exact
IP/prt from which the command originated.
This ensures correct routing of responses even in case multiple
programs are interfacing concurrently with a control socket.
Cherry-picked from: I24a0bba6eed059b101af95dac7d059f34dd715fc
Change-Id: I1f304ea887dc957d3ad53adb1e3c56ab27d8f196
Diffstat (limited to 'python/trx/udp_link.py')
-rw-r--r-- | python/trx/udp_link.py | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/python/trx/udp_link.py b/python/trx/udp_link.py index 1fae8b4..d96a6aa 100644 --- a/python/trx/udp_link.py +++ b/python/trx/udp_link.py @@ -45,13 +45,16 @@ class udp_link: # Check for incoming data if self.sock in r_event: data, addr = self.sock.recvfrom(128) - self.handle_rx(data.decode()) + self.handle_rx(data.decode(), addr) - def send(self, data): + def send(self, data, remote = None): if type(data) not in [bytearray, bytes]: data = data.encode() - self.sock.sendto(data, (self.remote_addr, self.remote_port)) + if remote is None: + remote = (self.remote_addr, self.remote_port) - def handle_rx(self, data): + self.sock.sendto(data, remote) + + def handle_rx(self, data, remote): raise NotImplementedError |