The implementation of TCPMasterConnection.connect means that there is no timeout for the 'Socket.connect' called by the 'Socket' constructor. This causes the thread to hang indefinitely.
public synchronized void connect() throws Exception {
if (! isConnected()) {
if (Modbus.debug)
System.out.println("connect()");
m_Socket = new Socket(m_Address, m_Port);
m_Socket.setReuseAddress(true);
m_Socket.setSoLinger(true, 1);
m_Socket.setKeepAlive(true);
prepareTransport();
m_Connected = true;
}
}// connect
I suspect this can be solved by replacing
m_Socket = new Socket(m_Address, m_Port);
with
m_Socket = new Socket();
setTimeout(m_Timeout);
m_Socket.connect(new InetSocketAddress(m_Address, m_Port), m_Timeout);
Thanks! Judging from the closing "// connect" comment on the end of that method, that's code I've never had a chance to review / clean up since forking the project. I'll take a look and hopefully push a change tonight or tomorrow.
Note that I will be migrating the entire project to GitHub in the near future, but this change should be made here.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Version: j2mod-1.06.jar
The implementation of TCPMasterConnection.connect means that there is no timeout for the 'Socket.connect' called by the 'Socket' constructor. This causes the thread to hang indefinitely.
I suspect this can be solved by replacing
with
I have not tested this, please investigate.
PS; This code snippet is up to date, checked against:
https://sourceforge.net/p/j2mod/code/HEAD/tree/trunk/src/com/ghgande/j2mod/modbus/net/TCPMasterConnection.java
Thanks! Judging from the closing "// connect" comment on the end of that method, that's code I've never had a chance to review / clean up since forking the project. I'll take a look and hopefully push a change tonight or tomorrow.
Note that I will be migrating the entire project to GitHub in the near future, but this change should be made here.
also, please note there is no tag for the 1.06 release which makes it hard to create a patched jar
Thanks - I'll try and remember to tag the new change when I make it.