Replacement for Apache Commons Net?

Since time immemorial (or at least since before I started working on it) the ipbridge in the Lutron binding has been using the org.apache.commons.net.telnet package to open telnet control connections to various Lutron bridge devices. However, over the past few months I’ve been getting ForbiddenPackageUsageCheck warnings on it from the static code analyzer. I’ve been diligently ignoring these for a while now, because I’m not too thrilled at the prospect of having to rip it out and replace it with something else.

So if usage of the Apache Commons Net library in general (and the telnet package in particular) is being deprecated, what is the recommended replacement? The support that it provides for various common network protocols seems like something very useful to have available by default in home automation software.

Long story short: a Socket or SocketClient.

When looking into the code of org.apache.commons.net.telnet you will see that TelentClient extends Telnet and Telnet extends SocketClient. It creates a VT100 connection (see code of TelnetClient).

The client creates the super classes and will sets the DEFAULT_PORT to 23.

Now, have a look into the connect(InetAddress host, int port) method from SocketClient.java. It is creating a new Socket using the DefaultSocketFactory, which is a TCP socket to specified host and port.

Reading and writing to the socket should not be a problem anymore. You can maybe spawn a new.Thread or use OHC thread pool for a scheduled reading (similar to what is done by the avmfritz call monitor).

I hope this helps.

Thanks. Yeah, that’s more or less the answer I expected, although I was hoping there might be more of a drop-in replacement available. SocketClient is also provided by Apache Commons, so that pretty much just leaves using a raw Socket. Easy enough if I were writing it from scratch, but doing a rip & replace in old code is more messy.

It’s not an issue for this binding, but what’s the answer for replacing all of the other protocols supported by Apache Commons Net?

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.