Occasionally I have the need to write some communications software, typically something that connects to a serial or TCP port, writes requests and reads responses, writing the results into a database.
Usually the basics are simple enough to achieve, but the challenge is in making a robust solution that will cope with lost connections and any other variety of reasons why things might go wrong (including bugs in the script itself).
What is the "best" way to approach something like this? Are some programming languages better than others for this? What's the best way to ensure a script restarts if it fails for some reason?
I'm looking for something Debian/Ubuntu based if relevant.
[Aside: One reason for asking is that I have been playing with an app I downloaded that talks to CurrentCost power meters, with a PHP-based web interface and a Python-based daemon, and I'm not sure why Python was chosen for it; also I note that the daemon regularly crashes on my system leaving me without any data.]