# Xmmp4r and backgroundrb

**URL:** <https://www.ruby-forum.com/t/xmmp4r-and-backgroundrb/180616>\
**Category:** Rails\
**Created:** [December 23, 2009, 6:00am UTC](https://www.ruby-forum.com/t/xmmp4r-and-backgroundrb/180616 "2009-12-23T06:00:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![murraj](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f6c823/32.png) [@murraj](https://www.ruby-forum.com/u/murraj)\
**Post date:** [December 23, 2009, 6:00am UTC](https://www.ruby-forum.com/t/xmmp4r-and-backgroundrb/180616/1 "2009-12-23T06:00:57Z")

</div>

Hello all,

Subject: Not able to return object from backgroundrb worker

I am trying to use xmpp4r and backgroundrb for my chat application.  
I am able to create a connectnion with XMPP4r through a worker in  
backgrounddrb.  
I have the problem in returning the object from the worker to my rails  
application.

My code is as follows:

class ChatWorker \< BackgrounDRb::MetaWorker  
require ‘xmpp4r’  
require ‘xmpp4r/bytestreams’  
require ‘xmpp4r/roster/helper/roster’  
require ‘xmpp4r/roster/iq/roster’  
include Jabber  
Jabber::debug = true

set\_worker\_name :chat\_worker  
def create(args = nil)  
# this method is called, when worker is loaded for the first time  
logger.info ‘Initializing Chat Worker…’  
end  
def connect\_chat(args)  
logger.info “Conencting chat…#{args[:username]} --”  
jid = Jabber::JID.new(args[:username])  
@client = Jabber::Client.new(jid)  
@client.connect  
@client.auth(args[:password])  
@client.send(Jabber::Presence.new.set\_show(nil).set\_status(‘From  
Rails!’))  
logger.info “Chat Connection status - #{@client.is\_connected?}”  
return @client.is\_connected?  
end  
def connected?  
return @client.is\_connected?  
end  
def get\_buddies  
if self.connected?  
@buddy\_list = []  
roster = Jabber::Roster::Helper.new(@client)  
mainthread = Thread.current  
roster.add\_query\_callback { |iq|  
mainthread.wakeup  
}  
Thread.stop  
roster.groups.each { |group|  
roster.find\_by\_group(group).each { |item|  
@buddy\_list \<\< item#[{:name =\> item.iname, :jid =\> item.jid,  
:subscription =\> item.subscription}]  
}  
}  
logger.info “Buddies\n#{@buddy\_list.inspect}”  
return @buddy\_list  
end

end

When i call the connect\_chat worker method from console i am able to  
connect to the server as below.  
MiddleMan.worker(:chat\_worker).connect\_chat(:arg =\> {:username =\>  
‘removed\_email\_address@domain.invalid’,:password =\> ‘xxxx’})

But when i try to call the get\_buddies worker method, i am not able to  
get the buddy list as below.  
MiddleMan.worker(:chat\_worker).get\_buddies  
Even in the log file, i printed the @buddy\_list object and its showing  
the correct result. But it is not returning the result.

The problem is with result returning.

Could you please help me in solving the issues. I am struggling with  
this for the whole day.

Thank you for your any kind of suggestions.

Regards  
Murugaraj B

---

<div class="post-metadata">

**Author:** ![murraj](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/f6c823/32.png) [@murraj](https://www.ruby-forum.com/u/murraj)\
**Post date:** [December 24, 2009, 4:53am UTC](https://www.ruby-forum.com/t/xmmp4r-and-backgroundrb/180616/2 "2009-12-24T04:53:02Z")

</div>

Anybody please help me !
