【发布时间】:2016-06-15 10:45:08
【问题描述】:
我正在尝试使用 XMPP Smack Api(4.1.4) 创建多用户聊天。我已经建立了一个登录连接,
XMPPTCPConnectionConfiguration.Builder configBuilder = XMPPTCPConnectionConfiguration.builder();
configBuilder.setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);
configBuilder.setResource(RESOURCE);
configBuilder.setServiceName(DOMAIN);
configBuilder.setHost(HOST);
XMPPTCPConnection connection = new XMPPTCPConnection(configBuilder.build());
connection.addConnectionListener(connectionListener);
AsyncTask<Void, Void, Boolean> connectionThread = new AsyncTask<Void, Void, Boolean>() {
@Override
protected Boolean doInBackground(Void... arg0) {
try {
connection.connect();
if(connection != null) {
PingManager mPingManager = PingManager.getInstanceFor(connection);
mPingManager.setDefaultPingInterval(1000 * 50);
mPingManager.setPingInterval(1000 * 50);
connection.setPacketReplyTimeout(1000 * 50);
mPingManager.registerPingFailedListener(new PingFailedListener() {
@Override
public void pingFailed() {
// TODO Auto-generated method stub
Log.e("PING", "ping failed");
// AGain Reconnecting code here..
}
});
}
} catch (IOException | SmackException | XMPPException e) {
Log.d(LOCAL_TAG, "connectConnection exc: "+e.getMessage());
}
return null;
}
};
connectionThread.execute();
它已成功连接。连接后,我正在尝试使用创建群聊,
try {
SharedPreferences mPreferences = context.getSharedPreferences("App_Pref", Context.MODE_PRIVATE);
String userJid = userJidAddress(with local ip);
String userName = "Test5";
Log.d(LOCAL_TAG, "createGroupChat jid: "+userJid+" -- connection.getServiceName(): "+connection.getServiceName());
MultiUserChatManager manager = MultiUserChatManager.getInstanceFor(connection);
MultiUserChat muc = manager.getMultiUserChat(userJid);
muc.create("InstantRoom");
Log.d(LOCAL_TAG, "createGroupChat -- Group CEATED Successfully ");
Form form = muc.getConfigurationForm();
Form submitForm = form.createAnswerForm();
List<FormField> fields = form.getFields();
Log.d(LOCAL_TAG, "createGroupChat -- fields.size(): "+fields.size());
for (int i = 0; i < fields.size(); i++) {
FormField field = (FormField) fields.get(i);
if (!FormField.Type.hidden.equals(field.getType()) && field.getVariable() != null) {
submitForm.setDefaultAnswer(field.getVariable());
}
}
List owners = new ArrayList();
owners.add("test5"+connection.getServiceName());
owners.add("test7"); //Another user
submitForm.setAnswer("muc#roomconfig_roomowners", owners);
submitForm.setAnswer("muc#roomconfig_persistentroom", true);
muc.sendConfigurationForm(submitForm);
muc.join("InstantRoom");
}
catch(Exception e){
Log.d(LOCAL_TAG, "createGroupChat -- Exception: "+e.toString());
}
但是在创建组时,我得到一个例外
"org.jivesoftware.smack.SmackException$NoResponseException: No response received within reply timeout. Timeout was 50000ms (~50s). Used filter: AndFilter: (FromMatchesFilter (full): test5@172.21.4.199/instantroom, StanzaTypeFilter: org.jivesoftware.smack.packet.Presence)."
如果我增加 PingIntervals 和 PacketReplyTimeout 毫秒,那么我会收到一条消息
"Thread[5,tid=4403,WaitingInMainSignalCatcherLoop,Thread*=0xb8e933a8,peer=0x12c000a0,"Signal Catcher"]:对信号 3 做出反应。
没有该例外,应用程序设置为自动强制关闭。希望如此,我在 muc.create("InstantRoom") 行收到异常,因为我无法在该行之后获取日志。 任何人都可以通过找出我做错了什么以及为什么我收到此错误以及在此之后如何继续来帮助我。提前致谢。
【问题讨论】:
-
好吧,发布你的代码(使用 muc.create() );)
-
@MrPk 您好,感谢您的回复。我已经编辑了我的代码,请检查它并给我一些建议。