我正在创建一个聊天应用程序,一对一聊天是正常工作,但当谈到多用户聊天我不能听他们的消息,我正在使用smack实现xmpp协议这里是代码
服务器配置部分是
public void serverCongig() throws XMPPException {
LOGGER.info(String.format("Initializing connection to server %1$s port
%2$d", server, port));
SmackConfiguration.setPacketReplyTimeout(packetReplyTimeout);
config = new ConnectionConfiguration(server,
port,PropertyReader.getPropertiesValue("server_domain"));
// config.setSASLAuthenticationEnabled(false);
config.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);
connection = new XMPPConnection(config);
try
{
connection.connect();
LOGGER.info("Connected: " + connection.isConnected()+" Service
name"+connection.getServiceName());
chatManager = connection.getChatManager();
messageListener = new MyMessageListener();
}
catch(Exception e)
{
callThread();
e.printStackTrace();
}
finally
{
callThread();
}
}
消息侦听部分是mymessagelistener类实现的messagelistener{
@Override
public void processMessage(Chat chat, Message message) {
try
{
String from = message.getTo();
String body = message.getBody();
String toUser="";
LOGGER.info(String.format("Received message '%1$s' from %2$s", body, from));
String[] user=from.split("@");
for(int i=0;i<user.length;i++)
toUser=user[0];
LOGGER.info("Receiver Phone number"+toUser);
SendMsgToWhatsapp create=new SendMsgToWhatsapp();
try {
if(!body.equalsIgnoreCase(null))
{
create.processWhatsappMessage(toUser, body);
}
} catch (Exception ex) {
callThread();
//logger.getlogger(xmppmanager.class.getname()).log(level.severe,null,ex);}}catch(异常e){e.printstacktrace();callthread();}}
暂无答案!
目前还没有任何答案,快来回答吧!