Chat.CreateMessege

Hi i’‘m having problems with creating to many chat instances when sending messeges, every time i send a chat i have the createMessege(); in the sending method which starts a new chat each time, and this causes the returning messenger to send back a reply to all the instances i’'ve created?

is there any way to have this call out side this method and have a nextmessege(); method inside or something to that effect.

here is the sending method if it helps any?

void sendIM(ActionEvent e)

{

String now = ntime.getHrMin();

try

{

/***

  • Creating a chat with the Chossen Person

*/

getUser();

PacketFilter filter = new PacketTypeFilter (Message.class);

con.addPacketListener (this, filter);

Chat newChat = con.createChat (user);

System.out.println(user);

/*******************************************************************

  • Getting the Message and sending it to the desired recipient

******************************************************************/

String text = messageField.getText();

conversation.append("(“now”)“newuser.getUsername()” :"+text + “\n”);

Message msg = newChat.createMessage();

msg.setBody(text);

newChat.sendMessage(msg);

//MessageEventManager.addNotificationsRequests(msg, true, true, true, true);

messageField.setText ("");

messageField.selectAll();

}

catch (Throwable t)

{

t.printStackTrace (System.out);

}

is there a way if creating a global chat instance or message instance that can be used???

thanks

Bob

Also, Is there any way to remove the resource from an incoming packet, As this is preventing me from recognising the user correctly, or is there a work around for this.

Thanks

Bob

I got the Message porblem fixed, i just instantiated the Chat variable in a different method and delayed the tread,

I’'m having another problem though, I have a message listener in the IM sender, the actually

frame used to send and receive the messages, and also on where the Roster is, i’'m having a problem that when the message is received it triggers both listeners, Is there anyway to specify which listener to use??

Hey Bob,

The idea of the listeners is to be notified when a new packet is received if the packet matches the used filter when adding the listener. So your options are: 1) Change the filter when adding the listeners, 2) Add an IF statement in the listener to ignore the packet according to your needs or 3) Review the whole design and maybe use one listener or different listeners for different packets filter.

Regards,

– Gato

Thanks Gato,

I’‘ll have a look at it again, I’‘m just having a problem recognising which user the packet is coming from, I’‘m still having a problem with the resource being sent with packet, when i try get from(); My system can’‘t understand where it’'s comeing from because of the resource, As all my users are on local host.

Thanks Anyway

Bob

Hey Bob,

I will need information about what you are trying to do and how you are doing it. After reading your code it seems to me that there is only one connection that is sending messages to other users.

Why are you having problems getting the sender of the message? What kind of problems are you having? Could you give me some example? Are you using anonymous users? Are you using the same user for all the connections with different resources?

Thanks,

– Gato

Ah i actually got it sorted, it only happened when i was trying to send msgs from exodus to my client, I created two instances of my client and it all seemed to work ok,

Sorry about that, ( i think i’'m going it in the wrong way but it seems to work!!!).

, I’‘m having a little problem with getting the presence now, this is a snippet of my code, I’‘m not enitrely sure that this is the correct way to go about it but i seem to get a nulpointer no matter what i do, I’‘m using it to populate the tree so it’'s important enough i think.

If i try to just print out the presence from Presence p = roster.getPresence(User);

it prints out either null or available available ,

I’'d really appreciate a little help.

if(presence.getType() == Presence.Type.AVAILABLE)

{

if(presence.getMode() == Presence.Mode.AWAY)

{

// CODE TO POPULATE THE JTREE

//

}