Showing posts with label xmpp. Show all posts
Showing posts with label xmpp. Show all posts

Saturday, May 26, 2018

Retrieving Archived messages from XMPP server in ios

Leave a Comment

I am integrating XMPP functionality in my ios app and i came across a problem i cannot solve. The problem is i cannot get archived messages from the server. My client is able to log in and i have tested several service calls (send, receive messages, getting info about a user) with success.

Upon sending

<iq type='get' id='pref1'>   <pref xmlns='urn:xmpp:archive'/> </iq> 

The response is

SEND: <iq type="get"><pref xmlns="urn:xmpp:archive"/></iq>  RECV: <iq xmlns="jabber:client" type="error" to="1@iis2/ae76edc"><error code="501"     type="cancel"><feature-not-implemented xmlns="urn:ietf:params:xml:ns:xmpp- stanzas"/</error></iq> 

The server administrator is able to see the archived messages, as he activated archiving.

Must something be done server or client side in order to achieve this functionality? Could it be that seeing old messages and the server actually implementing and supporting XEP-0136, are two different things?

0 Answers

Read More

Thursday, June 16, 2016

ReconnectionManager is not working correctly

Leave a Comment

I am using smack library to implement chat solution in android. It is making connection with openfire perfectly but reconnection is not working at all.

I have a lost a connection on a device, on connection receive it does not reconnect or call any callbacks of reconnect. Please suggest how we can reconnect to openfire using ReconnectManager.

private boolean openConnection(String account, String password) {     try {         if (null == xmppConnection || !xmppConnection.isAuthenticated()) {             XMPPTCPConnectionConfiguration.Builder config = XMPPTCPConnectionConfiguration.builder();             config.setHost(Constants.XMPP_SERVER_DOMAIN);             config.setServiceName(Constants.XMPP_SERVER_DOMAIN);             config.setPort(Constants.XMPP_SERVER_PORT);             config.setUsernameAndPassword(account, password);             //config.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);             config.setCompressionEnabled(true);             config.setDebuggerEnabled(true);              TLSUtils.acceptAllCertificates(config);              xmppConnection = new XMPPTCPConnection(config.build());             xmppConnection.setPacketReplyTimeout(10000);             ReconnectionManager.getInstanceFor(xmppConnection).enableAutomaticReconnection();             connectionListener = new XmppConnectionListener();             packetListener = new XmppPacketListener();              xmppConnection.addAsyncPacketListener(packetListener, new PacketFilter() {                 @Override                 public boolean accept(Stanza packet) {                     return true;                 }             });              xmppConnection.addConnectionListener(connectionListener);             xmppConnection.connect().login();             return true;         }     } catch (XMPPException xe) {         xe.printStackTrace();         xmppConnection = null;     } catch (IOException io) {         io.printStackTrace();         xmppConnection = null;     } catch (SmackException se) {         se.printStackTrace();         xmppConnection = null;     } catch (NoSuchAlgorithmException e) {         e.printStackTrace();         xmppConnection = null;     } catch (KeyManagementException e) {         e.printStackTrace();         xmppConnection = null;     }     return false; } 

XmppConnectionListener.java

public class XmppConnectionListener implements ConnectionListener {       private static final String TAG = "XmppConnectionListener";       @Override      public void reconnectionSuccessful() {          Log.d(TAG, "reconnectionSuccessful()");      }       @Override      public void reconnectionFailed(Exception arg0) {          Log.d(TAG, "reconnectionFailed()");      }       @Override      public void reconnectingIn(int arg0) {          Log.d(TAG, "reconnectingIn()");      }       @Override      public void connectionClosedOnError(Exception arg0) {          Log.d(TAG, "connectionClosedOnError()");      }       @Override      public void connected(XMPPConnection connection) {          Log.d(TAG, "connected()");      }       @Override      public void authenticated(XMPPConnection connection, boolean resumed) {          Log.d(TAG, "authenticated()");       }       @Override      public void connectionClosed() {          Log.d(TAG, "connectionClosed()");      }  } 

0 Answers

Read More

Saturday, April 23, 2016

XMPP app terminate and not recive message

Leave a Comment

I am working in XMPP Application. When I terminate and kill My Application than,

1)User is Not Connected In XMPP Server. User is Offline. But I want User is Connected and Online. Like Whats App(Appliction).

2)I can't get Any Messages From XMPP Server Side at that time,

- (void)xmppStream:(XMPPStream *)sender didReceiveMessage:(XMPPMessage *)message 

This method is not call. So, How Can I get Messages ?

And i also implement Pushnotification but in this way same issue Like,When app is Kill and Terminate than,This method is not call,

- (void)application:(UIApplication )application didReceiveRemoteNotification:(NSDictionary )userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))handler  

So, Please Guide me In Proper Way and Suggest me How to work as like same Whats App(Application).

Also, We can't set VOIP Flag In .plist file Because this way is not Proper and reject by the apple.

My Goal is Only Notification Work As like Whats App.

5 Answers

Answers 1

1)User is Not Connected In XMPP Server. User is Offline. But I want User is Connected and Online. Like Whats App(Appliction).

Once you closed or minimized WhatsApp the user gets offline (tested on iPhone4s), and messages received in this state are as push notifications.

2)I can't get Any Messages From XMPP Server Side at that time,

  • (void)xmppStream:(XMPPStream *)sender didReceiveMessage:(XMPPMessage *)message

This method get called only when application is active. So you can not get messages here after you killed your application.

- (void)application:(UIApplication )application didReceiveRemoteNotification:(NSDictionary )userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult result))handler  

This method will get called in following scenarios

  1. If your app is active and you got any new push notification.
  2. If your app is in background or killed or not started then system will show only notification on the top bar, once user tapped on notification it will open your application and then the method will get called.

And of course you can not use VOIP.

WhatsApp shows custom notification when user is active in WhatsApp. You need to send push notification for every message of your conversation. In this case

  1. If user is active then show your custom notification in app.
  2. If user is inactive (i.e. killed or minimized app) then system will show Notification in notification center.

When user taps on notification, system will launch application, and you have to check for app launching conditions (from which source app launched) and according to conditions join server/chat (or groups if you are using group chat).

Once you joined server with your name/nickname, you will get recent chats. You can also get history, you need to specify while joining chat server / group.

Make sure you are disconnecting from server and also from group when your app is getting minimized or killed. Use following methods to disconnect and/or related changes

 1. - (void)applicationDidEnterBackground:(UIApplication *)application  2. - (void)applicationWillTerminate:(UIApplication *)application 

Hope this will help you, I have implemented same to achieve expected results as WhatsApp.

Answers 2

First of all, If your application is terminated then you will receive Push Notification data in

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 

in launchOptions dictionary with key

 if (launchOptions)     {         if ([launchOptions valueForKey:UIApplicationLaunchOptionsRemoteNotificationKey])         {         // Your code         }     } 

Second, you can use background fetch for retrieving user's message, While background fetch you can connect your stream and fetch messages from XMPP server.

NOTE: WhatsApp's (iOS) version, fetches the message as soon as you open the app, it is connecting to the stream and then fetches the messages.

However you can implement your own logic to customize your functionality.

Answers 3

When your app kill, that time XMPP Deactivate all service.So, you can send webservice to server which can tell - you are offline.

Then after sever can send you Push notification all chat content.

Answers 4

Read the following document it will help you. http://xmpp.org/extensions/xep-0168.html

We ned to add priority when the presence of user is set as below:

-(void)GoOnline{  XMPPPresence *goOnline = [XMPPPresence presence]; NSXMLElement *priority = [NSXMLElement elementWithName:@"priority" stringValue:@"-1"]; [goOnline addChild:priority]; [xmppStream sendElement:goOnline]; } 

Now to know more about priority, it's role and how it works, read the document from above link.

Hope it may help you :)

Answers 5

Check this link and read the Remote Notifications (iOS 7 and Greater) section which is combining the Background Modes and Remote notifications to download content before launching the app.

You will get the idea and you can implement in your preferred language obj-c or swift.

Read More

Saturday, March 19, 2016

feature not implemented nodejs xmpp android

Leave a Comment

I am trying to create a chat application with out using Google message services and with nodejs xmpp server. So I used this node js xmpp server and smack api for android app.

I dont know why but server is sending stanza saying feature not implemented.

android code which I wrote to connect xmpp server.

XMPPTCPConnectionConfiguration config = XMPPTCPConnectionConfiguration.builder()                     .setServiceName("localhost")                     .setHost(IPADRESS)                     .setPort(5222)                     .build();             AbstractXMPPConnection conn2 = new XMPPTCPConnection(config);             conn2.setPacketReplyTimeout(1000);             SmackConfiguration.DEBUG = true;             conn2.connect();              conn2.login(mngr.getDeviceId(), "secret"); 

nodejs xmpp server module

var startServer = function (done) {   // Sets up the server.   server = new xmpp.C2S.TCPServer({     port: 5222,     domain: 'localhost'   })    // On connection event. When a client connects.   server.on('connection', function (client) {     // That's the way you add mods to a given server.      // Allows the developer to register the jid against anything they want     client.on('register', function (opts, cb) {       console.log('REGISTER')       cb(true)     })      // Allows the developer to authenticate users against anything they want.     client.on('authenticate', function (opts, cb) {       console.log('server:', opts.username, opts.password, 'AUTHENTICATING')       if (opts.password === 'secret') {         console.log('server:', opts.username, 'AUTH OK')         cb(null, opts)       } else {         console.log('server:', opts.username, 'AUTH FAIL')         cb(false)       }     })      client.on('online', function () {       console.log('server:', client.jid.local, 'ONLINE')      client.send("")      })      // Stanza handling     client.on('stanza', function (stanza) {       console.log('server:', client.jid.local, 'stanza', stanza.toString())       var from = stanza.attrs.from       stanza.attrs.from = stanza.attrs.to       stanza.attrs.to = from       client.send(stanza)     })     // Stanza handling     client.on('chat', function (stanza) {       console.log('server:', client.jid.local, 'chat', stanza.toString())       client.send(stanza)     });      // On Disconnect event. When a client disconnects     client.on('disconnect', function () {       console.log('server:',  'DISCONNECT')     })   })    server.on('listening', done) } startServer(function (){      console.log("server localhost started at 5222 localport"); }); 

nodejs server console output.

server localhost started at 5222 localport server: 354223060799129 secret AUTHENTICATING server: 354223060799129 AUTH OK server: 354223060799129 ONLINE server: 354223060799129 stanza <iq id="eW469-5" type="get" xmlns:stream="http://etherx.jabber.org/streams" from="354223060799129@localhost/Smack"><query xmlns="jabber:iq:roster"/></iq> server: 354223060799129 stanza <presence id="eW469-6" xmlns:stream="http://etherx.jabber.org/streams" from="354223060799129@localhost/Smack"/> server: 354223060799129 stanza <iq id="eW469-5" type="error" xmlns:stream="http://etherx.jabber.org/streams" from="354223060799129@localhost/Smack"><error type="cancel"><feature-not-implemented xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/></error></iq> 

android logs:

03-10 22:57:12.598 8126-8183/gcm.play.android.samples.com.gcmquickstart E/AbstractXMPPConnection: Exception in packet listener                                                                                                   java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.Object.hashCode()' on a null object reference                                                                                                       at java.util.concurrent.ConcurrentHashMap.get(ConcurrentHashMap.java:746)                                                                                                       at org.jivesoftware.smack.roster.Roster$PresencePacketListener.getUserPresences(Roster.java:1134)                                                                                                       at org.jivesoftware.smack.roster.Roster$PresencePacketListener.processPacket(Roster.java:1157)                                                                                                       at org.jivesoftware.smack.AbstractXMPPConnection$4.run(AbstractXMPPConnection.java:1156)                                                                                                       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)                                                                                                       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)                                                                                                       at java.lang.Thread.run(Thread.java:818) 03-10 22:57:12.598 8126-8185/gcm.play.android.samples.com.gcmquickstart E/Roster: Exception reloading roster                                                                                   XMPPError: feature-not-implemented - cancel                                                                                       at org.jivesoftware.smack.AbstractXMPPConnection$5.processPacket(AbstractXMPPConnection.java:1448)                                                                                       at org.jivesoftware.smack.AbstractXMPPConnection$3.run(AbstractXMPPConnection.java:1126)                                                                                       at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)                                                                                       at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)                                                                                       at java.lang.Thread.run(Thread.java:818) 

I tried so many solution for the similar type of question in stackoverflow but didnt work.help will be appreciated.

1 Answers

Answers 1

The node XMPP server project you linked is not a complete XMPP server. Its a XMPP server library which helps you to build a XMPP server with node.js.

In your log it returns the not implemented exception when you try to request the roster (contact list).

You either have to implement all the features you need in Javascript, or choose another existing feature complete XMPP software.

Read More