I'm trying to write a simple XMPP application on Android using asmack, but I've encountered a problem that I cannot login to several jabber servers. For example, I can't login into my test Openfire server, although the code works fine with jabber.org accounts.
Login code:
public void login() throws XMPPException
{
if (connection != null && connection.isConnected())
{
try
{
Random generator = new Random();
int resource_int = generator.nextInt();
connection.login(USERNAME, PASSWORD,
"Smack_" + Integer.toString(resource_int));
}
catch (XMPPException e)
{
e.printStackTrace();
connection.disconnect();
setConnection(null);
throw e;
}
Roster.setDefaultSubscriptionMode(Roster.SubscriptionMode.accept_all);
}
}
As I said, it works with jabber.org, but Openfire returns not-authorized(401) error. How can I fix it?
I never used Openfire, but I'm sure there is a Logfile somewhere - can you post it?
IIRC in Android some security functions (not sure if for SSL or TLS) are not compatible to Smack or Asmack, maybe thats the problem. In this case there is a way to solve it by using an own Socket connection (instead of the included SSL functions of Smack) - To verify this you can port your (XMPP-relevant) code to PC and use the Standard Smack Library.
Another point is, that there are different Smack ports for Android. I personally use the Asmack port from the Beem-project (because the originally Asmack had some issues - but I can't remember which ones...)
But still...without more information I can only guess.
Are you sure that you have the same account and password on the OpenFire server? Try logging into your server using the same username and password with an existing XMPP client. Take Android out of the equation altogether and make sure you can log into both servers first.
Related
I am trying to implement a chat functionality in my android app using XMPP over WebSockets.
I was able to find a library (org.igniterealtime.smack), but the connection is established over TCP and not over WebSockets, which I don't want.
Does anybody had to implement the same functionality and can point me in the right direction?
Websocket support for Smack is tracked as SMACK-835. It is currently in Smack's main branch and scheduled to become the Smack 4.5 release.
You can use it right now by consuming either Smack pre-releases or the nightly artifacts from https://www.igniterealtime.org/archiva/repository/maven/
Not sure if it's OK and doesn't violate TOS and whatnot but first sentence implies general guidance for XMPP + WebSocket and not strictly asking for Smack answer so - you could use JaXMPP library (https://github.com/tigase/jaxmpp), which already supports WebSocket and and is compatible with Android (StorkIM, https://github.com/tigase/stork is based on it).
It's quite easy to establish WebSocket connection (even encrypted):
JID user = JID.jidInstance("user#example.com/resource");
String password = "password";
Jaxmpp contact = new Jaxmpp();
contact.getModulesManager().register(new MessageModule());
contact.getConnectionConfiguration().setConnectionType(ConnectionConfiguration.ConnectionType.websocket);
contact.getConnectionConfiguration().setBoshService("wss://xmpp.example.com:5291");
contact.getConnectionConfiguration().setUserJID(user.getBareJid());
contact.getConnectionConfiguration().setUserPassword(password);
try {
contact.login(true);
if (contact.isConnected()) {
contact.disconnect();
}
} catch (Exception e) {
e.printStackTrace();
}
(disclaimer: I'm from Tigase team, which created both JaXMPP and StorkIM)
try {
String urlImage="https://maps.googleapis.com/maps/api/staticmap?center=0,0&zoom=1&size=100x100&key=AIzaSyD_GK1iiZD2kV5J_v6";
System.out.println(urlImage);
bitmap1 = BitmapFactory.decodeStream((InputStream) new URL(urlImage).getContent());
} catch (Exception e) {
e.printStackTrace();
}
when i call this url i get
javax.net.ssl.sslhandshakeexception:Handshake failed
exception how can i solve it
Based from this related SO post, you need to obtain the public certificate from the server you're trying to connect to. Try contacting the server admin and asking for it, using openssl to download it, or, since this appears to be an HTTP server, connecting to it with any browser, viewing the page's security info, and saving a copy of the certificate. As stated also in this documentation, this can happen for several reasons, including:
The CA that issued the server certificate was unknown
The server certificate wasn't signed by a CA, but was self signed
The server configuration is missing an intermediate CA
You can check the documentation which discussed how to address these problems while keeping your connection to the server secure.
I need to send a push notificiation from a webapp to an android app.
Basically I just want to inform the android client that new data is available on the server. So it only has to be a string + vibration/sound of the phone.
The (big) problem here is that I am inside a corporate network without access to the internet. This is why I cannot use GCM.
So far I found the following options to accomplish the task without GCM:
Use XMPP
WebSockets
Ajax Polling
Is it possible to include WebSockets or AjaxPolling into a native Android app to trigger events like vibrate?
Is there an easier solution, without that much overhead as with xmpp, since I just need to send a short notification? So far I understand that I need somethink like SMACK XMPP for Android + e.g. Openfire and XMPPHP on the server side for this scenario.
Since nobody replied, I want to provide you with an approach I now try to pursue.
I use Laravel to write the API. It comes with an out-of-the-box support for Redis, which is awesome to Broadcasts Events -> https://laravel.com/docs/5.1/events
The following is just a quick example:
Redis::publish('test', json_encode($data));
Those events are received from a Socket.IO Server-Instance running on the same machine.
var Redis = require('ioredis');
var redis = new Redis();
redis.subscribe('test');
....
server.listen(3000);
Socket.IO has an android client implementation, which allows me to connect to the socket.io server in a native android app.
Here is an example: http://socket.io/blog/native-socket-io-and-android/
private Socket mSocket;
{
try {
mSocket = IO.socket("http://localhost:3000");
} catch (URISyntaxException e) {}
}
I've successfully compiled Liblinphone library for android and use it to register to Brekeke SIP server and make calls between Android clients and PC client(x-Lite,linphone). but I'm facing two problems:
Client register to the server with their IP address instead of the domain.
For e.g: if the server IP:192.168.10.105 and client (IP,name):(192.168.10.101,101),
the user will registered to Brekeke as sip:101#192.168.10.101 instead of sip:101#192.168.10.105 so when I call 101 from linphone client the result is Not Found
try{
from = LinphoneCoreFactory.instance()
.createLinphoneAddress("sip:101#192.168.10.105");
proxy_cfg = LinphoneCoreFactory.instance().createProxyConfig
("sip:101#192.168.10.105","sip:"+from.getDomain(),null,true);
} catch (LinphoneCoreException e) {
FileLog.e("proxy_cfg error",e);
}
LinphoneAuthInfo info;
info = LinphoneCoreFactory.instance().createAuthInfo(from.getUserName(),
"password",null,"sip:"+from.getDomain());
mLinphoneCore.addAuthInfo(info);
try {
mLinphoneCore.addProxyConfig(proxy_cfg);
} catch (LinphoneCoreException e) {
FileLog.e("reg error",e);
}
mLinphoneCore.setDefaultProxyConfig(proxy_cfg);
I need to create user on the SIP server from the client side by code, is this possible using Liblinphone or I should implement it by my self?
Simply by using DNS SRV which keep tracking the clients IP
I am attempting to run gcm server using node-xmpp, but xmpp client does not seem to open at all and closes after timeout.
var xmpp = require('node-xmpp-client');
var options = {
type: 'client',
jid: 'fake-project-123#gcm.googleapis.com',
password: 'ApiKeyHere',
port: 5235,
host: 'gcm.googleapis.com',
legacySSL: true,
preferredSaslMechanism : 'PLAIN'
};
console.log("Creating XMPP Application");
var cl = new xmpp.Client(options);
cl.on('online', function()
{
console.log("XMPP Online");
});
Rest of the code was omitted. In the console, I never get to see "XMPP Online".
How do I check if xmpp is even connecting, and where it fails to open?
I got the same problem and found out that the Connection.startStream() was never called, although the socket was opened successfully.
Here's my pull request:
https://github.com/node-xmpp/node-xmpp-client/pull/61
Until it gets merged, you can use my fork, which should work for GCM:
https://github.com/Riplexus/node-xmpp-client
I followed this from gcm google groups and it worked for me.
And for timeouts you can try
xmppClient.connection.socket.setTimeout(0)
xmppClient.connection.socket.setKeepAlive(true, 10000)
Don't forget to whitelist your server ip in google console.
I have given up the hope of using node-xmpp and game smack client a try. Sadly it did not work, but I did get an error saying my project is not whitelisted. When project is whitelisted, it can receive messages from android devices, which is exactly what I need and is the sole reason why I went straight to CCS (XMPP). Without the whitelist, it is not possible to use CCS (XMPP) for sending the messages to android devices. In order to use HTTP method, the project does not need to be whitelisted, but has a limitation to being able to send messages only. I have signed up upstream GCM but have yet to receive response.
https://services.google.com/fb/forms/gcm/