powered by Jive Software

Procesar Mensajes con Smack de IM o Kraken

Hola, estoy utilizando las bibliotecas de smack para escuchar los mensajes conectado a OpenFire. Al open fire le instale el plugin de Kraken (antes era IM Gateway). Si me conecto con Spark, puedo escribir a los demas IM (MSN, Google Talk, etc.)

Si yo inicio el chat, si puedo ver las respuestas por medio del MessageListener. Pero si la otra parte (MSN, Talk, etc) inicio yo no puedo escuchar lo que me envían, solo si lo enviaron con Spark lo escucho, lo que estoy utilizando es:

Chat chat = connection.getChatManager().createChat(“jose.solares\40gmail.com@gtalk.127.0.0 .1”,

new MessageListener() {

public void processMessage(Chat chat, Message message) {

System.out.println("Received message: " + message);

System.out.println("Received message: "

  • message.getBody());

try {

chat.sendMessage(message);

} catch (XMPPException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

});

// User2 creates a MessageEventManager

MessageEventManager messageEventManager = new MessageEventManager(connection);

// User2 adds the listener that will react to the event notifications requests

messageEventManager.addMessageEventRequestListener(new DefaultMessageEventRequestListener() {

public void deliveredNotificationRequested(

String from,

String packetID,

MessageEventManager messageEventManager) {

super.deliveredNotificationRequested(from, packetID, messageEventManager);

// DefaultMessageEventRequestListener automatically responds that the message was delivered when receives this request

System.out.println(“Delivered Notification Requested (” + from + ", " + packetID + “)”);

}

public void displayedNotificationRequested(

String from,

String packetID,

MessageEventManager messageEventManager) {

super.displayedNotificationRequested(from, packetID, messageEventManager);

// Send to the message’s sender that the message was displayed

messageEventManager.sendDisplayedNotification(from, packetID);

}

public void composingNotificationRequested(

String from,

String packetID,

MessageEventManager messageEventManager) {

super.composingNotificationRequested(from, packetID, messageEventManager);

// Send to the message’s sender that the message’s receiver is composing a reply

messageEventManager.sendComposingNotification(from, packetID);

}

public void offlineNotificationRequested(

String from,

String packetID,

MessageEventManager messageEventManager) {

super.offlineNotificationRequested(from, packetID, messageEventManager);

// The XMPP server should take care of this request. Do nothing.

System.out.println(“Offline Notification Requested (” + from + ", " + packetID + “)”);

}

});

Chat chat = connection.getChatManager().createChat(“jxxxxxxxs\40gmail.com@gtalk.127.0.0.1” ,

new MessageListener() {

public void processMessage(Chat chat, Message message) {

System.out.println("Received message: " + message);

System.out.println("Received message: "

  • message.getBody());

try {

chat.sendMessage(message);

} catch (XMPPException e) {

// TODO Auto-generated catch block

e.printStackTrace();

}

}

});

// User2 creates a MessageEventManager

   MessageEventManager messageEventManager = new MessageEventManager(connection);

   // User2 adds the listener that will react to the event notifications requests

   messageEventManager.addMessageEventRequestListener(new DefaultMessageEventRequestListener() {

       public void deliveredNotificationRequested(

           String from,

           String packetID,

           MessageEventManager messageEventManager) {

           super.deliveredNotificationRequested(from, packetID, messageEventManager);

           // DefaultMessageEventRequestListener automatically responds that the message was delivered when receives this request

           System.out.println("Delivered Notification Requested (" + from + ", " + packetID + ")");

       }

       public void displayedNotificationRequested(

           String from,

           String packetID,

           MessageEventManager messageEventManager) {

           super.displayedNotificationRequested(from, packetID, messageEventManager);

           // Send to the message's sender that the message was displayed

           messageEventManager.sendDisplayedNotification(from, packetID);

       }

       public void composingNotificationRequested(

           String from,

           String packetID,

           MessageEventManager messageEventManager) {

           super.composingNotificationRequested(from, packetID, messageEventManager);

           // Send to the message's sender that the message's receiver is composing a reply

           messageEventManager.sendComposingNotification(from, packetID);

       }

       public void offlineNotificationRequested(

           String from,

           String packetID,

           MessageEventManager messageEventManager) {

           super.offlineNotificationRequested(from, packetID, messageEventManager);

           // The XMPP server should take care of this request. Do nothing.

           System.out.println("Offline Notification Requested (" + from + ", " + packetID + ")");

       }

   });