steveohara / j2mod

Enhanced Modbus library implemented in the Java programming language
Apache License 2.0
263 stars 112 forks source link

Add capability to bind the Socket to specific local interface. #135

Closed tamiradler closed 7 months ago

tamiradler commented 1 year ago

in the method com.ghgande.j2mod.modbus.net.TCPMasterConnection.connect(boolean), need the ability to bind the Socket to specific interface.

steveohara commented 9 months ago

Can you explain the use case you have for this? I'm struggling to understand why you wouldn't want to just rely on the OS to select the correct adapter for an outbound connection. The OS will figure out which network card to use based on your destination address and for that it uses routing tables etc.

steveohara commented 7 months ago

It was easy enough to add but tricky to test so there are no unit tests for it. I would appreciate it if you could take the snapshot for a spin and let me know if it meets your needs. New getter/setter added to TCPMasterConnection to allow the user to select a network interface to bind to.