steveohara / j2mod

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

what does the reconnecting in ModbusTCPMaster for? #99

Closed ltbyun closed 5 years ago

ltbyun 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