Upgrading default version of netcat could allow improved HA performance

The default version of netcat (nc) shipped with HA (at least on my odriod2) is a version from
busybox which lacks the -W option which other versions provide. Use of the -W option allows for the connection to be closed after receiving a specified number of data packets.

Without this, the only control over lifecycle is the --w (lowercase) option, which provides for a timeout in seconds.

A sample use case might be a command line shell script which sends a message over UDP and then exits as soon as a response is received. This can be achieved with the option nc -W 1 …
Lacking this option, the alternatives are either the script never returns, or else adding a timeout. If the timeout is too short then the response can be missed, increasing the timeout reduces the probability of this, but at the cost of the script blocking until the timer expires.

Additionally, the -W and -w options can be combined so that one can create a shell script which returns either when data is received or the timer expires, whichever happens first.

I This may be an upstream issue for busybox, but if there is some method for HA to override the default versions of binaries then I would strongly suggest doing so.

Don’t forget to vote for your own issue!

:grinning: :grinning: :grinning: …!!!

Voted for it but did you succeed to use properdy nc to send messages through a TCP connection ? Killing myself trying to get it to work in a shell_command but nothing happens :frowning:

Thanks

To my knowledge HA doesn’t need netcat for any particular functionality. Are you aware of anything in HA that depends on netcat? I’m guessing it simply comes packaged with something else that HA needs.

If that’s the case then HA is definitely not going to change anything about netcat on the offchance someone needs it in a shell command. If anything the devs would probably prefer to remove it (along with any other binaries that are unnecessary to HA functionality) to reduce the size of the image.

If you need this functionality I would suggest having your shell command ssh to a different container/machine. That way you have control over what is installed and can ensure your scripts dependencies are present.

I have managed through UDP, yes.

That is what I ended up doing, I have my switch controller running on a separate box (Raspberry Pi). But the only reason I need to run it on a separate box is due to the lack of a single command line option in the busybox version of nc.

Netcat is useful for communicating with some command line devices directly over TCP or UDP connections.
As mentioned, without the -W option, the only means to get such a command line connection to return is to use the timeout option. Obviously this needs to be sufficiently long to account for weak signals, hardware issues and so on, which means that scanning / polling can only be done slowly.

AS you mentioned, one solution is to run the integration on a remote device, but not everybody has a spare device lying around which can be dedicated to running a companion integration.

Sure I get it, for the (likely small) subset of folks that need to use netcat in their shell command the packaged binary isn’t useful to them. My point was that to my knowledge HA does not actually depend on netcat for anything, its only in the image because it came with something else. Or perhaps HA depends on something wich depends on netcat, I don’t know.

If you made a list of every single binary in the universe you could install on an alpine machine that some user somewhere might need in a shell command that would be an absolutely massive list. HA is not going to install every binary everyone might need. Nor is it going to give a way to customize the binaries in its container as that might mess with its dependencies and break it.

If you need a specific binary available for your shell commands then installing it somewhere else you can ssh to is really the only viable option. That being said that “somewhere else” doesn’t actually have to be a physical machine. I imagine many if not most users comfortable in shell scripting are also able to make a docker image. And if they can then there’s only a couple more steps to make that image into an addon so it runs right alongside HA.

Or alternatively you can install SSH & Web Terminal addon from the community addons repo. That does actually let you install additional packages in its container or run startup scripts to pull and make them from somewhere if necessary. And then you can set it up so HA can ssh into that container with a shell command.

Well the main concern here is that (for sure I probably missed something obvious) HA has no reliable and efficient system to program control of a device through basic ip communication such as telnet without being obliged to develop a proper integration which is very annoying :sleepy:

Indeed, which runs counter to the idea of command line entities, which is designed to be a quick and easy way for users to interact with devices without having to create an entire dedicated integration.
I get the point about not wanting to replace every single binary, however nc / netcat is THE most basic way of communicating across networks (other than having to mess around with low level socket code directly). Since almost everything that HA interfaces with communicates via some kind of network link, then it is not an exaggeration to say that there should be a simple and efficient way to that via the commandline. If curl lacked some vital feature would you say, “oh well, curl is just another binary”. Well curl is just a glorified version of netcat with HTTP or FTP or whatever built on top of that. It would be pretty inconvenient if curl didn’t have the ability to send a GET and receive a response from a web server and then return, but instead had a fixed timeout measured in seconds, regardless of whether it received a response or not.

What’s wrong with the telnet integration?

Sorry no offense but I don’t name that an integration as it can only do on/off and read a sensor :smiley: I need to be able to send different commands at device such as audio switch, video switch, volume commands… It’s very annoying that Telnet integration is not expendable to add your own commands :frowning:

Ah so you want to be able to create a telnet media player. Yea you’d need a feature request for that. You’re right, it only supports the switch platform currently.

Sort of but even media player is not really adapted for that ! It’s an audio matrix so media_player class doesn’t really fit ! It would need to be customisable so you can put in it commands you want and not be restricted at an existing set :slight_smile:

Telnet can only communicate with other telnet hosts. It’s a command protocol, like ftp, ssh, not a network protocl like UDP or TCP.