admin管理员组文章数量:1631138
很多聊天室客户端都使用了xmpp协议。
这个协议被人们诟病很多,但是对于简单的消息传送还是有很大的使用价值的。
XMPP is the open standard for messaging and presence。
gloox is a popular library for the Extensible Messaging and Presence Protocol (XMPP), formerly known as Jabber.
所以写了一个简单的例子,如何使用gloox连接服务器,监听消息,以及如何应答。
首先是设置 MessageHandler:
class Bot : public MessageHandler {
public:
Bot() {
JID jid("bot@localhost");
client = new Client( jid, "botpwd" );
connListener = new ConnListener();
client->registerMessageHandler( this );
client->registerConnectionListener(connListener);
client->connect(true);
}
这里我们创建了一个客户端,有ID和密码。
接下来,我们需要ConnectionListener就处理连接。
而ConnectionListener一定要registered with 客户端。这个一会再说。
现在是连接服务器,我们采用non-bloking的方式。
为了能够处理消息,我们要实现handleMessage方法:
virtual void handleMessage( const Message& stanza, MessageSession* session = 0 ) {
cout << "Received message: " << stanza << endl;
Me
版权声明:本文标题:windows客户端开发--xmpp协议gloox库 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://www.elefans.com/xitong/1729088583a1185887.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论