powered by Jive Software

Problem while receiving message using PacketListener

Hi

I am using Jive messenger Server and Smack API.I tried the following code

inorder to receive a message.But somehow it doesnt work.I am new to this

smack development.Please help.

I am using JBother as client.If i send a message to user Tom using Jbother i aint receiving any messages.Could anyone provide a sample code?

Code is as given below

public class JabberUtil {

public static void main(String[] args) {

JabberUtil jb=new JabberUtil();

jb.startProcess();

}

public void startProcess(){

try{

XMPPConnection connection= new XMPPConnection(Jivemessengerserver);

XMPPConnection.DEBUG_ENABLED = true;

connection.addPacketListener(new PacketListener(){

public void processPacket(Packet packet) {

Message message = (Message)packet;

System.out.println(message.getFrom());

System.out.println(message.getBody());

}

} ,new PacketTypeFilter(Message.class));

connection.login(“tom”, Jivemessengerserver);

System.out.println(“Connected”);

}

catch(XMPPException xe){

xe.printStackTrace();

}

}

}

Are you receiving the messages in the debugger?

When i write a program to send and then receive a message it works , i can see

the result in the debugger as well, but when i send a message through jbother

client, i dont see any message being received.

My problem is resolved, Code is correct.Thanks

I still need a sample code to show me how i should packet listener

Do i need to use a while loop for the listener.When i send a message through

jBother to a userit does not receive messages.I later on found that the user

didnt not ahve subscription rights.Please provide me some code sample

about using PAcket listener to receive messages

I am AFRAID PEOPLE DONT SEEM TO RESPOND MUCH ! I THOUGHT THE FORUM WAS MORE HELPFUL, BECAUSE THE DOCS DONT HELP MUCH

WHEN THERE IS LACK OF TIME.I AM NEW TO SMACK,SOMEONE RESPOND

Hi Gats,

Probably the reason no one is responding is because you said your problem was resolved.

Looking at your code, it appears you create a connection, log in and then your problem exits, so you are going to need some sort of loop so you can stay connected. Take a look at my url=http://www.jivesoftware.org/forums/thread.jspa?messageID=79370&#79370parrotbox example[/url] I posted awhile back for one solution on how to get around the problem you are having.

Hope that helps,

Ryan

I login within JBother, i add a new buddy in JBother.For example say Tom.

Now i write a program as shown above, wherein i

  1. Establish an XMPP connection

  2. connect Tom within my jive messenger server

  3. Add a packet lstener as shown in all code samples

In JBother when i drag over my mouse on buddy Tom it shows me

Subscriptions:None

Has subscriptions got to dowith sending and receiving messages?Trust me i couldnt get time to read the whole documentation.But if subscriptions do matter

then tell how do i set subscription of a user through smack api to ,from both??

Yesterday i tried my same code using on a buddy and it worked fine, i could receive messages alright.This buddy had subscription(Both).Now on Jbother

when i add a new buddy and run the same program it doesnt work!!

Has it got to do with user subscriptions in JBother???How do set buddy subscriptions???I tried the parrot bot code, i used tom in username-code

doesnt work

Where am i going wrong??is it the JBother subscription??Please help!!

messages

Question is unanswered

Have you tried a client other than JBother?

Thanks your advice was helpful,

I used Jeti client, it works well, the problem was with JBother.JBother has a strange problem, when i login into JBother through on instance of JBother client

and add my login as a buddy in another client, i dont see the buddy online.

If i open two instances of JBother and send messages between buddies

i dont see either of them online and i cant send messages.Strange isnt it?

Atleast you should see a logged in user online!!.

JETI works fine!!!so my problems is solved, the code works, thank you very much for your help.

Hi Gats,

I am happy to hear you managed to fix the problem you were having. I am not very familiar with JBother or JETI but I think it is always a good idea to test with as many different clients as you can.

Cheers,

Ryan