steveohara / j2mod

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

what does the reconnecting in ModbusTCPMaster for? #99

Closed bthulu closed 5 years ago

bthulu commented 5 years ago

even if reconnecting is false, ModbusTCPMaster still reconnect after socket closed. it seems that reconnecting has nothing to do

steveohara commented 5 years ago

The reconnect flag is added to every transaction - it is the transaction that decides (using that flag) if the connection should be closed after the transaction is complete. Take a look at ModbusTCPTransaction line 202

Perhaps the name of the flag is a bit miss-leading. What it actually means is "should I close the connection after each transaction?". There is a performance benefit if you keep the connection alive between the master and client if you have a lot of transactions to execute between them