camaya.net | Home of gloox – The Portable XMPP Engine
ちなみに 1.0 beta を使った
Gtalk に Hello!
#include <iostream> #include <gloox/client.h> #include <gloox/connectionlistener.h> #include <gloox/messagesession.h> class Bot : public gloox::ConnectionListener { public: Bot() : client_(gloox::JID("USER@gmail.com"), "PASS") { client_.registerConnectionListener(this); client_.setServer("talk.google.com"); session_ = new gloox::MessageSession(&client_, gloox::JID("USER@gmail.com")); client_.connect(); } virtual void onConnect() { session_->send("Hello, Hello!", "Hellooooooooo!"); client_.disconnect(); } virtual void onDisconnect(gloox::ConnectionError reason) { } virtual bool onTLSConnect(const gloox::CertInfo &info) { return true; } private: gloox::Client client_; gloox::MessageSession* session_; }; int main() { Bot bot; }
けっこうシンプルに書ける
Message のソース(生 XML)を見る
#include <iostream> #include <gloox/client.h> #include <gloox/connectionlistener.h> #include <gloox/messagesession.h> #include <gloox/messagehandler.h> #include <gloox/message.h> class Bot : public gloox::ConnectionListener, gloox::MessageHandler { public: Bot() : client_(gloox::JID("USER@gmail.com"), "PASS") { client_.registerConnectionListener(this); client_.setServer("talk.google.com"); session_ = new gloox::MessageSession(&client_, gloox::JID("USER@gmail.com")); session_->registerMessageHandler(this); client_.connect(); } virtual void onConnect() { session_->send("Hello, Hello!", "Hellooooooooo!"); } virtual void handleMessage(const gloox::Message &msg, gloox::MessageSession *session) { std::cout << msg.tag()->xml() << std::endl; // ここ } virtual void onDisconnect(gloox::ConnectionError reason) { } virtual bool onTLSConnect(const gloox::CertInfo &info) { return true; } private: gloox::Client client_; gloox::MessageSession* session_; }; int main() { Bot bot; }
割とすんなり試せた。 XMPP おもしろい