Menu

#37 Fix for long timeout opening TCPMasterConnection

v1.2rc1
closed-fixed
nobody
Transport (27)
5
2012-08-06
2008-12-03
John Belew
No

Running jamod-1.2rc1,
while trying to connect to an offline device using
TCPMasterConnection.connect()
I experienced very long (30 seconds or more) delays,
before connect() threw an exception.

My solution was to change replace this line in TCPMasterConnection.java connect()
m_Socket = new Socket(m_Address, m_Port);
with
// Create an unbound socket, THEN connect, blocking for max of m_Timeout milliseconds
// (if timeout occurs, SocketTimeoutException is thrown)
m_Socket = new Socket();
java.net.InetSocketAddress sockaddr = new java.net.InetSocketAddress( m_Address, m_Port );
m_Socket.connect( sockaddr, m_Timeout );

This defaults to a timeout of Modbus.DEFAULT_TIMEOUT (3000 milliseconds).

Discussion

  • Dieter Wimberger

    The problem with this approach is the fact that it would make jamod Java 1.4 dependent.

    Embedded devices we are working on offer Java 1.1, or reduced versions of it.

     
  • Dieter Wimberger

    • status: open --> closed-fixed
     

Log in to post a comment.