code: public synchronized boolean isConnected() {
          if (connected && socket != null) {
              if (!socket.isConnected() || socket.isClosed() || socket.isInputShutdown() || socket.isOutputShutdown()) {
                  try {
                      socket.close();
                  }
                  catch (IOException e) {
                      logger.error("Socket exception", e);
                  }
                  finally {
                      connected = false;
                  }
              }
              else {
                  /*
                   * When useUrgentData is set, a byte of urgent data
                   * will be sent to the server to test the connection. If
                   * the connection is actually broken, an IException will
                   * occur and the connection will be closed.
                   *
                   * Note: RFC 6093 has decreed that we stop using urgent
                   * data.
                   */
                  if (useUrgentData) {
                      try {
                          socket.sendUrgentData(0);
                          ModbusUtil.sleep(5);
                      }
                      catch (IOException e) {
                          connected = false;
                          try {
                              socket.close();
                          }
                          catch (IOException e1) {
                              // Do nothing.
                          }
                      }
                  }
              }
          }
          return connected;
      }
docs: Tests if this <tt>TCPMasterConnection</tt> is connected.
  
  @return <tt>true</tt> if connected, <tt>false</tt> otherwise.