xmppconn.getConnection().sendPacket(reg);到这就出问题,大婶 。。帮帮忙
一:用的asmack-android-17-0.8.3.jar
二:所有代码
System.out.println("----->register");
Registration reg = new Registration();
reg.setType(IQ.Type.SET);
String bb= xmppconn.getConnection().getServiceName();
reg.setTo(xmppconn.getConnection().getServiceName());
reg.setUsername(username);
reg.setPassword(password);
reg.addAttribute("android", "geolo_createUser_android");
System.out.println("reg:" + reg);
PacketFilter filter = new AndFilter(new PacketIDFilter(
reg.getPacketID()), new PacketTypeFilter(IQ.class));
PacketCollector collector = xmppconn.getConnection()
.createPacketCollector(filter);
xmppconn.getConnection().sendPacket(reg);
result = (IQ) collector.nextResult(SmackConfiguration
.getPacketReplyTimeout());
// Stop queuing results
collector.cancel();// 停止请求results(是否成功的结果)
if (result == null) {
Toast.makeText(getApplicationContext(), "服务器没有返回结果",
Toast.LENGTH_SHORT).show();
} else if (result.getType() == IQ.Type.ERROR) {
if (result.getError().toString()
.equalsIgnoreCase("conflict(409)")) {
Toast.makeText(getApplicationContext(), "这个账号已经存在",
Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(getApplicationContext(), "注册失败",
Toast.LENGTH_SHORT).show();
}
} else if (result.getType() == IQ.Type.RESULT) {
Toast.makeText(getApplicationContext(), "恭喜你注册成功",
Toast.LENGTH_SHORT).show();
}
xmppconn的代码如下
private static void openConnection() {
try {
// url、端口,也可以设置连接的服务器名字,地址,端口,用户。
ConnectionConfiguration connConfig = new ConnectionConfiguration(
"xxx.xxx.xxx.xxx", 5222);
connection = new XMPPConnection(connConfig);
connection.connect();
} catch (XMPPException xe) {
xe.printStackTrace();
}
}
public static XMPPConnection getConnection() {
try {
if (connection == null) {
configure(ProviderManager.getInstance());
openConnection();
}
} catch (Exception e) {
// TODO: handle exception
}
return connection;
}