AnsweredAssumed Answered

sending and receiving message through xmpp on android

Question asked by abhi on Jan 19, 2015
Latest reply on Jan 22, 2015 by ITr1ckst3rI

I am a beginner for chatting app. I searched and studied xmpp servers. I installed openfire xmpp server. The connection with xmpp server, registration and login tasks are done. Now i am trying to send and receive message. After user gets login and after that as user enters text to send. I used this code to send message

 

 

ChatManager chatmanager;
  chatmanager
= connection.getChatManager();
  
Chat newChat = chatmanager.createChat("cac6ba9dc9c6ac67"+"@pc", FirstPage.this);

  
try {
  newChat
.sendMessage("Howdy!");
  
}
  
catch (XMPPException e) {
  
System.out.println("Error Delivering block");
  
}

@Override
  
public void processMessage(Chat chat, Message message) {
  
// TODO Auto-generated method stub
  
Toast.makeText(FirstPage.this,"mssg: "+message.getBody(), Toast.LENGTH_SHORT).show();
  
switch (message.getType())
  
{
  
case chat:
  
String jsonData = (null==message.getBody())?"":message.getBody();

  
System.out.println(jsonData);
  
System.out.println(chat.getParticipant());
  
break;
  
case error:
  
break;
  
case groupchat:
  
break;
  
case headline:
  
break;
  
case normal:

  
break;
  
}
  
}

 

 

and this code I am using for receiving message, kindly see over this screenshot http://postimg.org/image/gd1mu8lbt/ to see users,

 

 

chatmanager.addChatListener(this);
  
PacketFilter filter = new MessageTypeFilter(Message.Type.chat);
  connection
.addPacketListener(this, filter);

@Override
  
public void chatCreated(Chat chat, boolean createdlocally) {
  
// TODO Auto-generated method stub
  
// System.out.println("1 message received "+chat.getParticipant());

  
if (!createdlocally) {
  
System.out.println("not created locally");
  
Toast.makeText(FirstPage.this, "not created locally", Toast.LENGTH_SHORT).show();
  chat
.addMessageListener(new MessageListener() {

  
@Override
  
public void processMessage(Chat arg0, Message arg1) {
  
// TODO Auto-generated method stub
  
//tv1.setText(arg1.getBody());
  
}
  
});
  
} else {
  
Toast.makeText(FirstPage.this, "created locally", Toast.LENGTH_SHORT).show();
  
System.out.println("created locally");
  
}
  
}

  
@Override
  
public void processPacket(Packet packet) {
  
// TODO Auto-generated method stub
  
System.out.println("in processPacket");
  
Message message = (Message) packet;
  
String body = message.getBody();
  
String from = message.getFrom();
  tv1
.setText("From "+from + "\n"+ body);
  
}

 

 

 

I am using this code don't know why the message is not sending over other side Can anyone please tell what mistake I am making or help in solving this problem

Outcomes