kochedykov / jlibmodbus

JLibModbus - is an implementation of the Modbus protocol v1.1b in java language. Java modbus library. It works. Welcome.
http://kochedykov.github.io/jlibmodbus/
Apache License 2.0
307 stars 128 forks source link

Multiple Listeners on Multihomed Host #66

Open btribley opened 3 years ago

btribley commented 3 years ago

I need three separate MODBUS slave servers listening on three different interfaces. Right now in file ModbusSlaveTCP.java:

synchronized public void listenImpl() throws ModbusIOException {
        try {
            server = new ServerSocket(tcp.getPort());

will respond to requests from any interface. I want this:

synchronized public void listenImpl() throws ModbusIOException {
        try {
            server = new ServerSocket(tcp.getPort(),100,tcp.getHost());

but don't want to screw the library up. Thinking that if tcp.getHost() returns something other than 0.0.0.0 then do the one that restricts the interface. The 100 is a default backlog, we could default it to 10 and add a constructor to TcpParameters to specify it if it comes to that.

Thoughts? I can do a pull for this, I am actively working a project with a short deadline... First thought was to just change it then go back and do it right!

shdk commented 3 years ago

There is already PR https://github.com/kochedykov/jlibmodbus/pull/61 for exactly the same thing. It is still pending to be merged though.