public static JmxManagerInfo askLocatorForJmxManager(InetAddress addr, int port, int timeout,
      boolean usessl) throws IOException {
    SocketAddress sockaddr = new InetSocketAddress(addr, port);
    Socket sock = ConnectionUtil.getSocketFactory(usessl).createSocket();
    try {
      sock.connect(sockaddr, timeout);
      sock.setSoTimeout(timeout);
      DataOutputStream out = new DataOutputStream(sock.getOutputStream());

      out.writeInt(GOSSIPVERSION);
      out.writeByte(DS_FIXED_ID_SHORT);
      out.writeShort(JMX_MANAGER_LOCATOR_REQUEST);
      out.flush();

      DataInputStream in = new DataInputStream(sock.getInputStream());
      byte header = in.readByte();
      if (header != DS_FIXED_ID_SHORT) {
        throw new IllegalStateException("Expected " + DS_FIXED_ID_SHORT + " but found " + header);
      }
      int msgType = in.readShort();
      if (msgType != JMX_MANAGER_LOCATOR_RESPONSE) {
        throw new IllegalStateException(
            "Expected " + JMX_MANAGER_LOCATOR_RESPONSE + " but found " + msgType);
      }
      byte hostHeader = in.readByte();
      String host;
      if (hostHeader == NULL_STRING) {
        host = "";
      } else if (hostHeader == STRING_BYTES) {
        int len = in.readUnsignedShort();
        byte[] buf = new byte[len];
        in.readFully(buf, 0, len);
        @SuppressWarnings("deprecation")
        String str = new String(buf, 0);
        host = str;
      } else {
        throw new IllegalStateException(
            "Expected " + STRING_BYTES + " or " + NULL_STRING + " but found " + hostHeader);
      }
      int jmport = in.readInt();
      boolean ssl = in.readBoolean();
      if (host.equals("")) {
        jmport = 0;
      }
      return new JmxManagerInfo(host, jmport, ssl);
    } finally {
      try {
        sock.close();
      } catch (Exception ignored) {
      }
    }
  }
Ask a locator to find a jmx manager. The locator will start one if one is not already running.

@param addr the host address the locator is listening on
@param port the port the locator is listening on
@param timeout the number of milliseconds to wait for a response; 15000 is a reasonable default
@return describes the location of the jmx manager. The port will be zero if no jmx manager was
        found.
@throws IOException if a problem occurs trying to connect to the locator or communicate with
        it.
geode-pulse/src/main/java/org/apache/geode/tools/pulse/internal/data/JmxManagerFinder.java