XMPP的Client
可以和tigase server .openfire 等主流XMPP服务器连接,
需要用到smack 包
/**
* TestXMPPClient
* @author Charles
* @email chs.garea@gmail.com
*
* */
package com.gareatech.testxmpp;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import org.jivesoftware.smack.ConnectionConfiguration;
import org.jivesoftware.smack.PacketListener;
import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smack.ConnectionConfiguration.SecurityMode;
import org.jivesoftware.smack.XMPPException;
import org.jivesoftware.smack.filter.AndFilter;
import org.jivesoftware.smack.filter.PacketFilter;
import org.jivesoftware.smack.packet.IQ;
import org.jivesoftware.smack.packet.Packet;
import org.jivesoftware.smack.packet.Registration;
/**
* @param arg[0] XMPP Server
* @param arg[1] Thread Number
* @param arg[2] Debug Mode 1,
* TestXMPPClient 192.168.10.106 10 1
* */
public class TestXMPPClient {
public static void main(String[] arg) throws InterruptedException {
boolean Debug = false;
String XMPPserver = "192.168.10.106";
int number = 0;
switch (arg.length)
{
case 2:
XMPPserver = arg[0];
number = Integer.parseInt(arg[1]);
break;
case 3:
XMPPserver = arg[0];
number = Integer.parseInt(arg[1]);
if(arg[2].equals("1"))
Debug = true;
break;
default:
System.out.println("Wrong Paramenters");
return;
}
System.out.println("server:"+XMPPserver+"\nnumber:"+number+"\nDebug:"+Debug);
for( int i = 0; i<number; i++)
{
new MitiSay(i+"",XMPPserver,Debug).start();
Thread.sleep(1000);
}
}
}
/**
* 线程
*
* */
class MitiSay extends Thread {
private String XMPPServer;
private boolean DebugFlag ;
public MitiSay(String threadName) {
super(threadName);
this.XMPPServer = "192.168.10.106";
this.DebugFlag = false;
}
public MitiSay(String threadName,String XMPPserver) {
super(threadName);
this.XMPPServer = XMPPserver;
this.DebugFlag = false;
}
public MitiSay(String threadName,String XMPPserver,boolean DebugFlag) {
super(threadName);
this.XMPPServer = XMPPserver;
this.DebugFlag = DebugFlag;
}
public void run() {
System.out.println("线程"+getName() + " 开始!");
XMPPConnection.DEBUG_ENABLED = DebugFlag;
ConnectionConfiguration connectionConfig = new ConnectionConfiguration("192.168.10.106", 5222, "pc-201012031249");
connectionConfig.setSecurityMode(SecurityMode.required);
connectionConfig.setSASLAuthenticationEnabled(false);
connectionConfig.setCompressionEnabled(false);
//connectionConfig.setSelfSignedCertificateEnabled(true);
try {
/** Connection **/
XMPPConnection connection = new XMPPConnection(connectionConfig);
PacketFilter packetFilter = new AndFilter();
PacketListener packetListener = new PacketListener() {
@Override
public void processPacket(Packet packet) {
// TODO Auto-generated method stub
System.out.println("Thread"+getName()+"Get Message:"+packet.toXML());
if (packet instanceof IQ) {
IQ response = (IQ) packet;
if (response.getType() == IQ.Type.ERROR) {
if (!response.getError().toString().contains("409")) {
}
} else if (response.getType() == IQ.Type.RESULT) {
}
}
}
};
connection.addPacketListener(packetListener, packetFilter);
connection.connect();
System.out.println("connect! Next-> Register!");
/** Registration **/
final String newUsername = newRandomUUID();
final String newPassword = newRandomUUID();
Registration registration = new Registration();
registration.setType(IQ.Type.SET);
registration.setTo(XMPPServer);
Map paramenter = new HashMap();
paramenter.put("username", newUsername);
paramenter.put("password", newPassword);
paramenter.put("name", "new");
paramenter.put("email", "mail@mail.com");
registration.setAttributes(paramenter);
connection.sendPacket(registration);
System.out.println("registration! Next -> Login");
/** login **/
//connection.login("admin", "tigase");
connection.login(newUsername, newPassword);
System.out.println("Logged!!"+newUsername+"\n"+newPassword);
while (true)
{
Thread.sleep(500000000);
}
} catch (XMPPException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println(getName() + " 线程运行结束!");
}
/**
*
* newRandomUUID: 获取一随机数
*/
private static String newRandomUUID() {
String uuidRaw = UUID.randomUUID().toString();
return uuidRaw.replaceAll("-", "");
}
}
分享到:
相关推荐
erlang分布式 XMPP Seerlang分布式 XMPP Serverrvererlang分布式 XMPP Servererlang分布式 XMPP Server
分布式 XMPP Server 共32页.ppt
XMPP server:其内核是一个XMPP路由器,完成基本组件间的数据包交换和路由。 功能: 1.会话管理器:负责客户端会话认证,在线状态,用户联系表等 2.数据存储器(XDB):连接数据库系统,保持用户信息、通信日志等 3....
django-xmpp服务器测试 去做 分配分数
阅读许可证(你可以在这个 repo 的根目录中找到它)莉拉XMPP-Server 由 NodeJS 运行,用作 IRC 服务器的隧道。 现在,它从您可以 PM 的已定义渠道获取联系人。跑步使用 nodeJs 运行 run.js。 请注意,这将设置一个...
Learn about the fundamentals of XMPP and be able to work with the core functionality both server-side and in the browser Build a simple 1-to-1 chat (the "Hello World" of XMPP), explore multi-user chat...
注意:该项目已经生命尽头,我(消防和加油者,作者)将不会以任何形式改善或支持该项目。XMPP服务器另一个小型xmpp服务器如何设定: 使用您的IDE进行构建设置server.ini 许可证:GPLv3
jabber协议下得类vqq协议.开发环境vc6.0++ 支持msn,jabber,gmail
xmppserver-docker:Kontalk服务器Docker映像
xmpp Qt源码包 的server搭建
xmpp协议介绍PPT,详细介绍了XMPP核心协议方方面面
XMPP协议的中文版本,适合开发IM的学习。openfire是基于XMPP协议的消息服务器,能基于它实现IM功能的开发。
android的XMPP客户端
节点-xmpp-服务器惯用 XMPP 服务器库手动的有关如何使用node-xmpp-server说明,请参阅 。安装注意:我们现在只支持 nodejs 0.8.0 及更高版本。 使用包管理器 : npm install node-xmpp-server测试安装开发依赖项,...
xmpp协议和xmpp扩展协议,chm格式
基于XMPP的多方通信系统研究与实现.pdf 基于XMPP的P2P即时通信系统的研究及实现.kdh 基于SIMPLE和XMPP协议的移动IM研究.pdf XMPP研究与应用.pdf XMPP协议研究及其在IM系统群组通信中的应用.pdf XMPP协议分析及客户端...
XMPP协议分析,xmpp是即时通讯IM中比较普遍的应用
XMPP是一种基于XML的协议,它继承了在XML环境中灵活的发展性。因此,基于XMPP的应用具有超强的可扩展性。经过扩展以后的XMPP可以通过发送扩展的信息来处理用户的需求,以及在XMPP的顶端建立如内容发布系统和基于地址...
xmpp-androidPn的服务端和客户端打包
关于XMPP协议的说明及介绍,XMPP体系结构的组成,XMPP原理等的说明