Hi,i am an chinese student,i need ur help about xmpp!

hi.

i wrote a wildfire client. now it can comunicate with spark, but it can just send and recv messages.

so i want to achieve file transport between them.

can someone give me some help or ducument about xmpp file transport!.

thx very much!

Message was edited by: godsun

Hi 你好

There are 2 JEPs you might want to read:

JEP-0047: In-Band Bytestreams (IBB)

JEP-0065: SOCKS5 Bytestreams

The IBB is for low-bandwidth transfer, which is also a fallback method in case the SOCKS5 Bytestreams is not available.

Also, you may want to take a look at how we’‘ve implemented file transfer in Smack. Or, if you’'re using Smack, just use that code.

Regards,

Matt

thank q.

i use c++ to write programme, maybe smack is useless and i havn’'t learned java before.

i see the i IBB but i still do not know how to write the code.

Hi,

i use c++ to write programme, maybe smack is useless and i havn’'t learned java before.

There are a number of C and C++ code libraries for use in Jabber development that you can find in http://www.jabber.org/software/libraries.shtml. I use iksemel to develop external components because it’'s light weight and easy to use. So far, I find it very stable.

i see the i IBB but i still do not know how to write the code.

Yeah, you’‘re right! Reading the JEPs is a headache especially if you just need a quick solution. I’'d suggest that you run 2 clients with debug/packet exchange enabled and initiate a file transfer between them. Look at what are the packets being exchanged from the negotiation part till the end of file transfer. Make the JEPs as the reference and start to code.

p/s: I made the effort to learn Java a long time ago when the Internet was making its way. I found out that Java sucks! Since then C has always been my language of preference. But Wildfire made me read Java, and I finally realized that Java has indeed improved! Oh… part of the blame goes to Matt

Hi aznidin,

as there is a JEP one should really read it and not try to reverse-engineer what other clients do to initiate a file transfer. This may produce real problems if the client did not implement the JEP correctly.

And for students it’'s really a good task to read JEPs and use them to write code.

LG

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

Hi LG,

I don’‘t see that as a reverse engineering. It’‘s very much like showing an example. Students are better taught by showing working examples first. In fact I didn’‘t ignore the fact that the JEPs are the fundamental concept. That’'s why I mentioned in the end “Make the JEPs as the reference and start to code.”

Hi,

now i use gloox liberary.

Shall I use these two classes: InBandBytestreamManager,InBandBytestream.

I don’‘t use that library and so, I don’‘t have any idea. Looking at the name of the classes, I think you’‘re on the right track. Also that’'s all about C++. If you develop using Smack, it is more appropriate to discuss here and there might be people who can help in this forum.