Own network protocol

Tim Chase python.list at tim.thechases.com
Sat Dec 27 08:21:10 EST 2014


On 2014-12-27 01:56, pfranken85 at gmail.com wrote:
> I am just about setting up a project with an Raspberry Pi that is
> connected to some hardware via its GPIO pins. Reading the data
> already works perfectly but now I want to distribute it to clients
> running in the network. Hence, I have to setup a server in Python.
> 
> I do not want to reinvent the wheel, so I am asking myself whether
> there is a good practice solution. It should basically work such
> that once value (can be either binary or an analog value) has
> changed on the server, it should send the update to the connected
> clients. At the same time, it should be possible for the client to
> send a particular request to the server as well, i.e., switch on
> LED X.
> 
> What kind of protocol do you recommend for this? UDP or TCP? Do you
> recommend the use of frameworks such as twisted?

The eventual solution would depend on a variety of factors:

- how critical is synchronization?

- do clients need to know if they missed a message? (somebody
  disconnected from the LAN for a moment)

- do clients need a way to receive historical messages in the event
  they were offline during the broadcast? (a power outage knocked out
  Client #18 at the time of the last update)

- are all your clients on the same IP subnet? (you could use a
  broadcast packet)

- would you rather push data as it changes, or have clients poll for
  the current state? (you write "it should send the update to the
  connected clients" which suggests a push architecture, yet you also
  want to have clients able to send updates: "should be possible for
  the client to send a particular request to the server…i.e., switch
  on LEX X")

- are you concerned about security/authentication? Can a rogue device
  send a message pretending to be the server?  What would/should
  happen if an unintended client snoops the traffic? Does it matter?


The suggestions would look very different if you were just building a
hobby notification system as a demo in a contained home/lab/office,
vs. if you were building an industrial control system for monitoring a
remote location and conveying security info.

-tkc






More information about the Python-list mailing list