[ale] Python (or other) socket identification

Alex Carver agcarver+ale at acarver.net
Fri Feb 3 15:11:49 EST 2017


On 2017-02-03 04:18, Pete Hardie wrote:
> Perhaps using tcp (connection oriented) sockets, so you don't have to search for 
> the IP of the other end?


I am using TCP but that's not the reason for the tracking.  This is a
one-to-many issue.  The python is a daemon, multiple microdevices
(ethernet controlled relays) connect to it using a reusable socket.

I want to be able to send a command back to the relay so the concept is
that the daemon has a command queue available to it where I feed in an
IP (known a priori) and the command.  As the daemon loop runs, it checks
that queue for anything that it needs to process, pulls out the IP,
finds the matching socket and sends the data to that socket.

The IP is known because it's entered into a config file, something like:

relay1:  <IP1> <channel1>
relay2:	 <IP1> <channel2>
relay3:  <IP2> <channel1>
relay4:  <IP2> <channel2>

So the code would at some point decide it needs to send a command to
relay4.  It finds relay4's IP, looks through the listing to find the
corresponding socket and then does a send() on that socket with the
appropriate payload.

Problem is that if a socket closes, pulling up the IP address no longer
works because the connection is gone.  So I needed an alternate method
to find and purge.


More information about the Ale mailing list