gloox登录账号(OPENfire服务器)
2014-09-06 18:46
991 查看
#include "stdafx.h" #include "gloox/client.h" #include "gloox/connectionlistener.h" #include "gloox/disco.h" #include "gloox/message.h" #include "gloox/gloox.h" #include "gloox/loghandler.h" #include "gloox/tlshandler.h" #include "gloox/tlsdefault.h" #include "gloox/logsink.h" #include "gloox/messagehandler.h" #include "gloox/base64.h" #include "gloox/stanza.h" #include "gloox/lastactivity.h" #include "gloox/connectiontcpclient.h" #include "gloox/registrationhandler.h" #include "gloox/registration.h" #include "gloox/messageeventhandler.h" #include "gloox/chatstatehandler.h" #include "gloox/messagesessionhandler.h" using namespace gloox; #pragma comment(lib,"gloox-1.0.lib") #ifndef _WIN32 # include <unistd.h> #endif #include <stdio.h> #include <string> #if defined( WIN32 ) || defined( _WIN32 ) # include <windows.h> #endif using namespace gloox; #include <stdio.h> #include <locale.h> #include <string> #include <cstdio> // [s]print[f] class MessageTest : public MessageSessionHandler, ConnectionListener, LogHandler, MessageEventHandler, MessageHandler, ChatStateHandler { public: MessageTest() : m_session( 0 ), m_reconnect( false ) {} virtual ~MessageTest() {} void start() { JID jid( <a target=_blank href="mailto:bojie2017@121.42.13.133">bojie2017@121.42.13.133</a> );//账号匿名+创建的服务器名字 j = new Client( jid, "12345" );//账号密码 j->registerConnectionListener( this ); j->registerMessageSessionHandler( this, 0 ); j->disco()->setVersion( "reconnectTest", GLOOX_VERSION, "Linux" ); j->disco()->setIdentity( "client", "bot" ); j->disco()->addFeature( XMLNS_CHAT_STATES ); // j->setTls( TLSDisabled ); j->setCompression( false ); j->setStreamManagement( true, true ); StringList ca; ca.push_back( "/path/to/cacert.crt" ); j->setCACerts( ca ); j->logInstance().registerLogHandler( LogLevelDebug, LogAreaAll, this ); // // this code connects to a jabber server through a SOCKS5 proxy // // ConnectionSOCKS5Proxy* conn = new ConnectionSOCKS5Proxy( j, // new ConnectionTCP( j->logInstance(), // "sockshost", 1080 ), // j->logInstance(), "example.net" ); // conn->setProxyAuth( "socksuser", "sockspwd" ); // j->setConnectionImpl( conn ); // // this code connects to a jabber server through a HTTP proxy through a SOCKS5 proxy // // ConnectionTCP* conn0 = new ConnectionTCP( j->logInstance(), "old", 1080 ); // ConnectionSOCKS5Proxy* conn1 = new ConnectionSOCKS5Proxy( conn0, j->logInstance(), "old", 8080 ); // conn1->setProxyAuth( "socksuser", "sockspwd" ); // ConnectionHTTPProxy* conn2 = new ConnectionHTTPProxy( j, conn1, j->logInstance(), "jabber.cc" ); // conn2->setProxyAuth( "httpuser", "httppwd" ); // j->setConnectionImpl( conn2 ); ConnectionError ce = ConnNoError; if( j->connect( false ) ) { while( ce == ConnNoError ) { ce = j->recv(); } printf( "ce: %d\n", ce ); } m_reconnect = true; ce = ConnNoError; if( j->connect( false ) ) { while( ce == ConnNoError ) { ce = j->recv(); } printf( "ce: %d\n", ce ); } delete( j ); } virtual void onConnect() { printf( "connected!!!\n" ); } virtual void onDisconnect( ConnectionError e ) { printf( "message_test: disconnected: %d\n", e ); if( e == ConnAuthenticationFailed ) printf( "auth failed. reason: %d\n", j->authError() ); } virtual bool onTLSConnect( const CertInfo& info ) { time_t from( info.date_from ); time_t to( info.date_to ); printf( "status: %d\nissuer: %s\npeer: %s\nprotocol: %s\nmac: %s\ncipher: %s\ncompression: %s\n" "from: %s\nto: %s\n", info.status, info.issuer.c_str(), info.server.c_str(), info.protocol.c_str(), info.mac.c_str(), info.cipher.c_str(), info.compression.c_str(), ctime( &from ), ctime( &to ) ); return true; } virtual void handleMessage( const Message& msg, MessageSession * /*session*/ ) { printf( "type: %d, subject: %s, message: %s, thread id: %s\n", msg.subtype(), msg.subject().c_str(), msg.body().c_str(), msg.thread().c_str() ); if( msg.body().substr( 0, 3 ) == "ack" ) // using substr() to work around some stupid clients j->ackStreamManagement(); else if( msg.body().substr( 0, 3 ) == "req" ) j->reqStreamManagement(); else if( msg.body().substr( 0, 4 ) == "quit" ) j->disconnect(); else { std::string re = "You said:\n> " + msg.body() + "\nI like that statement."; m_session->send( re, gloox::EmptyString ); } } virtual void handleMessageEvent( const JID& from, MessageEventType event ) { printf( "received event: %d from: %s\n", event, from.full().c_str() ); } virtual void handleChatState( const JID& from, ChatStateType state ) { printf( "received state: %d from: %s\n", state, from.full().c_str() ); } virtual void handleMessageSession( MessageSession *session ) { printf( "got new session\n"); // this example can handle only one session. so we get rid of the old session j->disposeMessageSession( m_session ); m_session = session; m_session->registerMessageHandler( this ); } virtual void handleLog( LogLevel level, LogArea area, const std::string& message ) { printf("log: level: %d, area: %d, %s\n", level, area, message.c_str() ); if( message.substr( 0, 10 ) == "<stream:er" ) printf( "something's foul\n" ); //if( !m_reconnect && j->m_smHandled > 10 ) // j->disconnect( ConnTlsFailed ); // fake disconnect reason so that no </stream:stream> is sent } private: Client *j; MessageSession *m_session; bool m_reconnect; }; int main( int /*argc*/, char** /*argv*/ ) { MessageTest *r = new MessageTest(); r->start(); delete( r ); scanf("%s"); return 0; }
相关文章推荐
- Spark(windows)登录openfire服务器时一直报账号密码错误
- 有关域服务器免登录问题以及获取域服务器下所有登录账号【深海原创】
- android 中 smack重新登录openfire服务器
- 有关域服务器免登录问题以及获取域服务器下所有登录账号【深海原创】
- 如何使用H5判断登录页面手机号码长度是否正确和账号密码不能为空,从而减少对服务器的请求(注册也一样)
- 服务器客户端模拟账号密码登录
- openfire设置一个账号同时登录并可同时接收消息
- Openfire更改服务器domain属性后登录不了的解决方法
- 域服务器免登录问题以及获取域服务器下所有登录账号【深海原创】
- gloox 链接openfire服务器问题解决办法
- 使用同一账号在多个xmpp客户端连接openfire服务器的解决方案
- C#访问openfire服务器之三:一次成功的登录
- 解决SQL server 服务器升级到域控制器,删除账号报“删除该登录名前请撤消相应权限。”
- Android基于XMPP Smack Openfire开发IM【一】登录openfire服务器
- gloox 链接服务器问题 服务器是openfire
- gloox1.0使用Emai格式的账号登录
- 基于xmpp协议,openfire服务器,处理被挤下线,或因网络掉线,第二次无法登录的问题
- 基于xmpp协议,openfire服务器,处理被挤下线,或因网络掉线,第二次无法登录的问题
- 有关域服务器免登录问题以及获取域服务器下所有登录账号【深海原创】