I'm having trouble connection to my bosh server, it says it needs "sid":
org.igniterealtime.jbosh.BOSHException: Connection Manager session creation response did not include required 'sid' attribute
this is how I'm trying to connect / login:
BOSHConfiguration.Builder configBuilder = BOSHConfiguration.builder();
configBuilder.setUsernameAndPassword(USERNAME, PASSWORD);
configBuilder.setHost(HOST);
configBuilder.setPort(PORT);
configBuilder.setFile(FILE_PATH);
configBuilder.setUseHttps(true);
configBuilder.setServiceName(SERVICE);
AbstractXMPPConnection connection = new XMPPBOSHConnection(configBuilder.build());
try {
connection.connect();
} catch (SmackException e) {
I have same problem and resolved when I added below code :
Bytestream stream = new Bytestream();
stream.setSessionID(username);
configBuilder.setResource(stream.toXML().toString());
Related
I've started to develop an android chat application using Smack. The server I've been using is Ejabberd 4.2 which I want to connect it on the local machine using the emulator. This is the code to make a connection and print some log text:
try {
InetAddress address = InetAddress.getByName("10.0.2.2");
DomainBareJid serviceName = JidCreate.domainBareFrom("localhost");
XMPPTCPConnectionConfiguration config = XMPPTCPConnectionConfiguration.builder()
.setUsernameAndPassword(user,pass)
.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled)
.setXmppDomain(serviceName)
.setHostAddress(address)
.setPort(5222)
.setDebuggerEnabled(true)
.build();
AbstractXMPPConnection conn = new XMPPTCPConnection(config);
conn.connect();
if (conn.isConnected()){
Log.d(TAG, "connection established");
}
conn.login();
if (conn.isAuthenticated()){
Log.d(TAG, "connection authorized");
}
} catch (Exception e) {
e.printStackTrace();
}
I've used 10.0.2.2 as the localhost domain name for emulator, but it throws ConnectionException.
SmackException$ConnectionException: The following addresses failed:
'null:5222' failed because: /10.0.2.2 exception:
java.net.SocketTimeoutException: failed to connect
how to connect ejabbered server to android
ConnectionConfiguration config = new ConnectionConfiguration("http://localhost:5280/admin");
XMPPConnection connection = new XMPPConnection(config);
connection.connect();
connection.login("Test", "Test");// Log into the server
You may use Smack Android Clientfor that.
By using Smack creating a connection is as simple like
// Create the configuration for this new connection
XMPPTCPConnectionConfiguration.Builder configBuilder = XMPPTCPConnectionConfiguration.builder();
configBuilder.setUsernameAndPassword("username", "password");
configBuilder.setResource("SomeResource");
configBuilder.setXmppDomain("jabber.org");
AbstractXMPPConnection connection = new XMPPTCPConnection(configBuilder.build());
// Connect to the server
connection.connect();
// Log into the server
connection.login();
...
// Disconnect from the server
connection.disconnect();
Smack Documention
Smak 4.1.3 ServerName is the name of your server. ServerIp is the ip address of your server and mPort is port for xmpp server which is usually 5222.
And Make sure you have registered users for example in your case user "Test" should be registered.
XMPPTCPConnectionConfiguration config = XMPPTCPConnectionConfiguration.builder()
.setServiceName(serverName).setHost(serverIp)
.setPort(mport)
.setCompressionEnabled(false).build();
XMPPTCPConnectionconn conn= new XMPPTCPConnection(config);
conn.connect();
conn.login(username,password);
I am implementing a chat feature in my android app. So I have installed an open fire server and Smack Client library and now I have written a code to connect with the server but I am getting an error which states that ConnectionConfiguration is an abstract class.So i cant instaniate. Could you give me some idea about the instantiation of ConnectionConfiguration in SMACK 4.1?
Try to use the example below:
XMPPTCPConnectionConfiguration.Builder config = XMPPTCPConnectionConfiguration.builder();
config.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);
config.setUsernameAndPassword(USER_ID+ "#" + DOMAIN, key);
config.setServiceName(DOMAIN);
config.setHost(DOMAIN);
config.setPort(PORT);
config.setDebuggerEnabled(true);
config.setSocketFactory(SSLSocketFactory.getDefault());
mConnection = new XMPPTCPConnection(config.build());
try {
mConnection.connect();
} catch (SmackException | IOException | XMPPException e) {
e.printStackTrace();
}
Now I am working with XMPP-chat for Android using ejabberd server.
When I am trying to connect to the server, it shows an error. But it works fine in openfire server.
I am using smack library.
Error log is given below:
04-21 20:34:16.824: I/XMPPChatDemoActivity(1929): [SettingsDialog] Connected to 10.0.2.2
04-21 20:34:21.932: E/XMPPChatDemoActivity(1929): Failed to log in as test3#eworks.com
04-21 20:34:21.932: E/XMPPChatDemoActivity(1929): No response from the server.
I found solution how to connect to gtalk and jabber.org with Smack 3.1.0:
Code for GTalk:
ConnectionConfiguration cc = new ConnectionConfiguration("talk.google.com", 5222, "gmail.com");
XMPPConnection connection = new XMPPConnection(cc);
try {
connection.connect();
// You have to put this code before you login
SASLAuthentication.supportSASLMechanism("PLAIN", 0);
// You have to specify your gmail addres WITH #gmail.com at the end
connection.login("some.account#gmail.com", "password", "resource");
// See if you are authenticated
System.out.println(connection.isAuthenticated());
} catch (XMPPException e1) {
e1.printStackTrace();
}
For jabber.org here is the code:
ConnectionConfiguration cc = new ConnectionConfiguration("jabber.org", 5222, "jabber.org");
XMPPConnection connection = new XMPPConnection(cc);
try {
connection.connect();
// You have to put this code before you login
SASLAuthentication.supportSASLMechanism("PLAIN", 0);
// You have to specify your Jabber ID addres WITHOUT #jabber.org at the end
connection.login("your.jabber", "password", "resource");
// See if you are authenticated
System.out.println(connection.isAuthenticated());
} catch (XMPPException e1) {
e1.printStackTrace();
}
With this code i can now connect to my local ejabberd and openfire server. I hope this will solve your problems.
This is where I got the socketIO files from.
https://github.com/Gottox/socket.io-java-client/tree/master/src/io/socket
I am on the client side.
I know connecting works when the server does not need authentication.
But when it needs authentication (Username and password), I get a handshaking error message.
How do I get passed authentication?? Could it be a server side error? Would the server side of things change if authentication was added?
This is the function that throws an error...I did not write it.
This line is the one causing problems: InputStream stream = connection.getInputStream();
It says it is caused by: java.io.FileNotFoundException: url:80/socket.io/1/
private void handshake() {
URL url;
String response;
URLConnection connection;
try {
setState(STATE_HANDSHAKE);
url = new URL(IOConnection.this.url.toString() + SOCKET_IO_1);
connection = url.openConnection();
if (connection instanceof HttpsURLConnection) {
((HttpsURLConnection) connection)
.setSSLSocketFactory(sslContext.getSocketFactory());
}
connection.setConnectTimeout(connectTimeout);
connection.setReadTimeout(connectTimeout);
/* Setting the request headers */
for (Entry<Object, Object> entry : headers.entrySet()) {
connection.setRequestProperty((String) entry.getKey(),
(String) entry.getValue());
}
InputStream stream = connection.getInputStream();
Scanner in = new Scanner(stream);
response = in.nextLine();
String[] data = response.split(":");
sessionId = data[0];
heartbeatTimeout = Long.parseLong(data[1]) * 1000;
closingTimeout = Long.parseLong(data[2]) * 1000;
protocols = Arrays.asList(data[3].split(","));
} catch (Exception e) {
error(new SocketIOException("Error while handshaking", e));
}
}
Problem solved (sort of), here: Android developpement, Gottox socket.io-java-client: file not fount Exception /socket.io/1/
(try using an earlier version of socket.io - by first deleting socket.io folder from node_modules and then install an older version, e.g., 0.9.16, using this command: npm install socket.io#0.9.16)