smack 메시지 전송 및 수신
1457 단어 smack 메시지 전송 및 수신
/**
*
*@param con
*@param user JID
*@param msg
*/
@Override
public synchronized void sendMessages(XMPPConnection con,String user, String msg) {
if (null != user && !"@".equals(user))
{
user = user + "@" +con.getServiceName();
}
Chat chat=con.getChatManager().createChat(user, null);
try {
chat.sendMessage(msg);
} catch (XMPPException e) {
e.printStackTrace();
}
}
수신 정보:
/**
*
* @param con
*/
@Override
public void recieveMessage(final XMPPConnection con) {
final Map<String, String> params = new HashMap<String, String>();;
//final StringBuilder sb=new StringBuilder();
con.getChatManager().addChatListener(new ChatManagerListener() {
@Override
public void chatCreated(Chat chat, boolean arg1) {
chat.addMessageListener(new MessageListener() {
@Override
public void processMessage(Chat arg0, Message message) {
System.out.println(message.getFrom()+"-->"+message.getTo()+"
"+message.getBody());
}
});
}
});
//return sb.toString();
}