hi, thank you at the first.
now i use gloox liberary.
Shall I use these two classes: InBandBytestreamManager,InBandBytestream.
i want to make my client can transport file to the spark client.shall i use ibb_test.cpp.can u help me to modify the code.for example, i want to send a file “ss.txt” (in the local folder) to the the spark.
here is the test file:
#include “…/client.h”
#include “…/messagesessionhandler.h”
#include “…/messageeventhandler.h”
#include “…/messageeventfilter.h”
#include “…/chatstatehandler.h”
#include “…/chatstatefilter.h”
#include “…/connectionlistener.h”
#include “…/disco.h”
#include “…/stanza.h”
#include “…/gloox.h”
#include “…/lastactivity.h”
#include “…/loghandler.h”
#include “…/logsink.h”
#include “…/inbandbytestream.h”
#include “…/inbandbytestreammanager.h”
#include “…/inbandbytestreamhandler.h”
#include “…/inbandbytestreamdatahandler.h”
using namespace gloox;
#include
class IBBTest : public MessageSessionHandler, ConnectionListener, LogHandler,
MessageEventHandler, MessageHandler, ChatStateHandler, InBandBytestreamHandler,
InBandBytestreamDataHandler
;
virtual ~IBBTest() {};
void start()
{
setlocale( LC_ALL, “” );
JID jid( "hurkhurk@example.org/gloox" );
j = new Client( jid, “hurkhurks” );
j->setAutoPresence( true );
j->setInitialPriority( 4 );
j->registerConnectionListener( this );
j->setAutoMessageSession( true, this );
j->disco()->setVersion( “messageTest”, GLOOX_VERSION, “Linux” );
j->disco()->setIdentity( “client”, “bot” );
j->disco()->addFeature( XMLNS_CHAT_STATES );
StringList ca;
ca.push_back( “/path/to/cacert.crt” );
j->setCACerts( ca );
m_ibbManager = new InBandBytestreamManager( j, j->disco() );
m_ibbManager->registerInBandBytestreamHandler( this );
j->logInstance().registerLogHandler( LogLevelDebug, LogAreaAll, this );
if( j->connect(false) )
{
ConnectionError ce = ConnNoError;
while( ce == ConnNoError )
{
ce = j->recv();
if( m_send )
{
m_ibb->sendBlock( “some data!\n” );
printf( “sending\n” );
++c;
if( c == 10 )
m_send = false;
}
}
printf( “ce: %d\n”, ce );
}
// cleanup
if( m_session )
{
m_session->removeMessageHandler();
delete m_chatStateFilter;
delete m_messageEventFilter;
delete m_session;
}
delete( j );
}
virtual void onConnect()
{
printf( “connected!!!\n” );
JID jid( "you@example.org/res" );
m_ibbManager->requestInBandBytestream( jid, this );
};
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 )
{
printf( “status: %d\nissuer: %s\npeer: %s\nprotocol: %s\nmac: %s\ncipher: %s\ncompression: %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() );
return true;
};
virtual void handleMessage( Stanza *stanza )
{
printf( “type: %d, subject: %s, message: %s, thread id: %s\n”, stanza->subtype(),
stanza->subject().c_str(), stanza->body().c_str(), stanza->thread().c_str() );
std::string msg = "You said:\n> " + stanza->body() + “\nI like that statement.”;
std::string sub;
if( !stanza->subject().empty() )
sub = "Re: " + stanza->subject();
m_messageEventFilter->raiseMessageEvent( MessageEventDisplayed );
sleep( 1 );
m_messageEventFilter->raiseMessageEvent( MessageEventComposing );
m_chatStateFilter->setChatState( ChatStateComposing );
sleep( 2 );
m_session->send( msg, sub );
if( stanza->body() == “quit” )
j->disconnect();
}
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 )
{
// this will leak if you talk to this bot from more than one full JID.
m_session = session;
printf( “got new session\n”);
m_session->registerMessageHandler( this );
m_messageEventFilter = new MessageEventFilter( m_session );
m_messageEventFilter->registerMessageEventHandler( this );
m_chatStateFilter = new ChatStateFilter( m_session );
m_chatStateFilter->registerChatStateHandler( 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() );
};
virtual bool handleIncomingInBandBytestream( const JID& from, InBandBytestream *ibb )
{
m_ibb = ibb;
if( !m_session )
m_session = new MessageSession( j, from );
else
printf( “already have a session\n” );
m_ibb->attachTo( m_session );
m_ibb->registerInBandBytestreamDataHandler( this );
m_send = true;
return true;
};
virtual void handleOutgoingInBandBytestream( const JID& to, InBandBytestream *ibb )
{
printf( “got requested ibb\n” );
m_ibb = ibb;
if( !m_session )
m_session = new MessageSession( j, to );
else
printf( “already have a session\n” );
m_ibb->attachTo( m_session );
m_ibb->registerInBandBytestreamDataHandler( this );
m_send = true;
};
virtual void handleInBandBytestreamError( const JID& /remote/, StanzaError /se/ )
{
printf( “unused\n” );
};
virtual void handleInBandData( const std::string& data, const std::string& sid )
{
printf( “incoming data from stream %s: %s\n”, sid.c_str(), data.c_str() );
};
virtual void handleInBandError( const std::string& /sid/, const JID& /remote/, StanzaError /se/ )
{
printf( “unused\n” );
};
virtual void handleInBandClose( const std::string& /sid/, const JID& /from/ )
{
printf( “bytestream closed\n” );
};
private:
Client *j;
MessageSession *m_session;
MessageEventFilter *m_messageEventFilter;
ChatStateFilter *m_chatStateFilter;
InBandBytestreamManager *m_ibbManager;
InBandBytestream *m_ibb;
int c;
bool m_send;
};
int main( int /argc/, char* /argv[]/ )
{
IBBTest *r = new IBBTest();
r->start();
delete( r );
return 0;
return 0;
}
Message was edited by: godsun