modbus icon indicating copy to clipboard operation
modbus copied to clipboard

Allow starting server on existing listener

Open andig opened this issue 3 years ago • 6 comments

It would be nice- especially for testing- if an existing listener could be used instead of the server creating it's own listener. Doing so would also externalise the entire TLS checking/handling.

andig avatar Oct 29 '22 14:10 andig

I have- for sake of speed and being opinionated in terms of which changes were needed- created a fork at https://github.com/andig/mbserver. The main changes are:

  • start server on existing listener
  • removed the TLS handling- this may really be wrong but I feel this could/should be part of the calling application
  • removed the client- I'm typically relying on grid-x/modbus for that
  • some refactoring, especially around binary.ByteOrder
  • gofmted everything

My changes (which are really to large part removal) are in https://github.com/andig/mbserver. If this should be of any interest please let me know if PRs would be of interest. If possible I'd like not having to maintain a fork.

andig avatar Nov 01 '22 10:11 andig

Thanks for the heads up andig. I'll dig into your fork and see if there's anything there for me to backport.

simonvetter avatar Nov 01 '22 10:11 simonvetter

Out of interest, what custom TLS handling is your application doing?

simonvetter avatar Nov 01 '22 10:11 simonvetter

Really no TLS handling. I've sort of come from the "I want to determine the listener" side. Once I do that I can't have the TLS handling in the library. If that breaks things it may not be the way to go but is good enough for my purposes.

andig avatar Nov 01 '22 10:11 andig

I've opened https://github.com/simonvetter/modbus/pull/21 if you want to take a look. I've not rewritten the server tests yet as I'd need to migrate them to the grid-x client (or use simonvetter/modbus ;). The whole exercise allows to use the server component for building a modbus proxy in https://github.com/evcc-io/evcc/pull/4981. Having the proxy allows for sharing the modbus connection for devices that otherwise allow a single client only.

andig avatar Nov 01 '22 10:11 andig

@simonvetter I'd be happy to open a PR for gofmt and maybe golangcilint- that would already make the diff much smaller.

andig avatar Nov 01 '22 16:11 andig