Java - trying prebind converse.js using bosh but unable to get sid and get rid ... using smack bosh

I am trying to connect to an open fire using smack bosh and trying to prelink converse.js on a web page. My bosh code

BOSHConfiguration config = new BOSHConfiguration(false, "host", 7070, "/http-bind/", "<host>", "xmpp:127.0.0.1:5222");
BOSHConnection connection = new BOSHConnection(config);
try {
connection.connect();
connection.login("un", "pw");
String sss = connection.getConnectionID();
String bosh = connection.BOSH_URI;
} catch (Exception e) {
}

Can someone help me establish a bosh connection and get the required sid, rid and jid from the session ....

Any help is greatly appreciated.

+2
source share
2 answers

I managed to do this by adding the following functions to the Smack BOSHConnection library class:

public class BOSHConnection extends Connection {
    ...
    public String getSid() {
        return client.getSid();
    }

    public Long getRid() {
        return client.getRid();
    }
    ...
}

, Rid - , Smack, .

Jid BOSHConnection.getUser();

, , , Smack, BOSHConnection.login.

// Changed: preserve current api - call new pre-bind aware function
public void login(String username, String password, String resource)
        throws XMPPException {
    login(username, password, resource, false);         

}

// Added: Using original login function with prebind awareness
public void login(String username, String password, String resource, boolean preBind)         
        throws XMPPException {
    if (!isConnected()) {
        throw new IllegalStateException("Not connected to server.");
    }

    ... unchanged

    // Indicate that we're now authenticated.
    authenticated = true;
    anonymous = false;

    // Added: Prebind only requires connect and authenticate
    if (preBind) {
        return;
    }

-

// login with pre-bind only
connection.login(userName, password, "", true);

, , , - , . , XMPP- ( SMACK ), , , XMPP, - , .

: fooobar.com/questions/1553122/...

+4

, , , :

client.getRid/Sid. jbosh , , .

jbosh ( , ) :

In com.kenai.jbosh.BOSHClient class
//I introduced a new property
private Long rid;

//commented the following code
//long rid = requestIDSeq.getNextRID();
//and at that place added
this.rid = requestIDSeq.getNextRID();

//and finally added a new getter for rid
public Long getRid() {
    return rid;}

smack-bosh:

In BOSHConnection.java
public Long getRid() {
    return client.getRid();}
public String getSid() {
    return sessionID;}
+1

All Articles