[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

XMPP client with Ruby

Zablon Ochomo

1/25/2008 8:10:00 AM

Hi all,

Does anyone out there know how to implement an xmpp client to a server
like ejabberd using ruby?

Kindly, give me any links to resources.

--

Ochomo
--
Posted via http://www.ruby-....

10 Answers

Stephane Wirtel

1/25/2008 9:26:00 AM

0

Zablon Ochomo a écrit :
> Hi all,
>
> Does anyone out there know how to implement an xmpp client to a server
> like ejabberd using ruby?
>
> Kindly, give me any links to resources.
>
> --
>
> Ochomo
There are two xmpp library in the gem repository

Zablon Ochomo

1/25/2008 9:47:00 AM

0

Stephane Wirtel wrote:
> Zablon Ochomo a �crit :
>> Hi all,
>>
>> Does anyone out there know how to implement an xmpp client to a server
>> like ejabberd using ruby?
>>
>> Kindly, give me any links to resources.
>>
>> --
>>
>> Ochomo
> There are two xmpp library in the gem repository

thanks

I had downloaded the xmpp4r gem and installed.

thanks again
--
Posted via http://www.ruby-....

Zablon Ochomo

1/28/2008 7:05:00 AM

0

The code below is working with the xmpp4r form
http://home.gna.o...

require 'XMPP4R'
begin
# Connect to the server and set presence to available for chat.
jid = Jabber::JID.new('myjid@xmppserver/Resource')
client = Jabber::Client.new(jid, false)
client.connect
client.auth('passwd')
client.send(Jabber::Presence.new.set_show(:chat).set_status('Ruby!'))

# Send an Instant Message.
body = 'Hi XMPP'
to_jid = Jabber::JID.new('tojid@xmppserver')
message = Jabber::Message::new(to_jid,
body).set_type(:normal).set_id('1')
client.send(message)
end

question:

how do I receive messages, since I can only send?

---
ochomo
--
Posted via http://www.ruby-....

brabuhr

1/28/2008 3:46:00 PM

0

On Jan 28, 2008 2:04 AM, Zablon Ochomo <ochomoz@gmail.com> wrote:
> The code below is working with the xmpp4r form
> http://home.gna.o...
> ...
> how do I receive messages, since I can only send?

Try looking at some of the examples. If you installed the gem, then go to:
.../gems/xmpp4r-0.3.2/data/doc/xmpp4r/examples/

And, look for add_message_callback in the RDoc:
http://home.gna.o...rdoc/
http://home.gna.o...rdoc/classes/Jabber/Stream.html#M000487

examples/basic/echo_threaded.rb:
cl = Client::new(myJID)
cl.connect
...
cl.add_message_callback do |m|
if m.type != :error
puts m.body
end
end

Michael

1/28/2008 7:01:00 PM

0

On 1/28/08, Zablon Ochomo <ochomoz@gmail.com> wrote:
> how do I receive messages, since I can only send?

Something like that, i believe.

client.add_message_callback do |m|
print "#{m.from} - #{m.body}\n"
end

Zablon Ochomo

1/29/2008 6:17:00 AM

0

Thanks for your help.

I googled out on xmppr4-simple. It appears to easier and working well.
Here is the code that runs well with ejabberd sever:

require 'rubygems'
require 'xmpp4r-simple'
im = Jabber::Simple.new('zo@myejabberd','zo')

im.deliver('gm@myejabberd','hello xmpp')

puts 'send done'
sleep(3)

im.received_messages { |msg| puts "#{msg.body} #{msg.type}" }

im.disconnect

---

ochomo
--
Posted via http://www.ruby-....

Lokesh Agrawal

5/5/2008 6:41:00 AM

0

Hi Zablon,

When I am running your code i am getting error:


c:/ruby/lib/ruby/gems/1.8/gems/xmpp4r-0.3.1/lib/xmpp4r/connection.rb:53:in
`init
ialize': Bad file descriptor - connect(2) (Errno::EBADF)
from
c:/ruby/lib/ruby/gems/1.8/gems/xmpp4r-0.3.1/lib/xmpp4r/connection.r
b:53:in `new'
from
c:/ruby/lib/ruby/gems/1.8/gems/xmpp4r-0.3.1/lib/xmpp4r/connection.r
b:53:in `connect'
from
c:/ruby/lib/ruby/gems/1.8/gems/xmpp4r-0.3.1/lib/xmpp4r/client.rb:73
:in `connect'
from
c:/ruby/lib/ruby/gems/1.8/gems/xmpp4r-0.3.1/lib/xmpp4r/client.rb:60
:in `connect'
from
c:/ruby/lib/ruby/gems/1.8/gems/xmpp4r-0.3.1/lib/xmpp4r/client.rb:58
:in `each'
from
c:/ruby/lib/ruby/gems/1.8/gems/xmpp4r-0.3.1/lib/xmpp4r/client.rb:58
:in `connect'
from
c:/ruby/lib/ruby/gems/1.8/gems/xmpp4r-simple-0.8.4/lib/xmpp4r-simpl
e.rb:371:in `connect!'
from
c:/ruby/lib/ruby/gems/1.8/gems/xmpp4r-simple-0.8.4/lib/xmpp4r-simpl
e.rb:309:in `client'
from
c:/ruby/lib/ruby/gems/1.8/gems/xmpp4r-simple-0.8.4/lib/xmpp4r-simpl
e.rb:318:in `send!'
from
c:/ruby/lib/ruby/gems/1.8/gems/xmpp4r-simple-0.8.4/lib/xmpp4r-simpl
e.rb:134:in `status'
from
c:/ruby/lib/ruby/gems/1.8/gems/xmpp4r-simple-0.8.4/lib/xmpp4r-simpl
e.rb:85:in `initialize'
from gtalk123.rb:3:in `new'
from gtalk123.rb:3



Can you please help.


Regards
Lokesh Agrawal

Zablon Ochomo wrote:
> Thanks for your help.
>
> I googled out on xmppr4-simple. It appears to easier and working well.
> Here is the code that runs well with ejabberd sever:
>
> require 'rubygems'
> require 'xmpp4r-simple'
> im = Jabber::Simple.new('zo@myejabberd','zo')
>
> im.deliver('gm@myejabberd','hello xmpp')
>
> puts 'send done'
> sleep(3)
>
> im.received_messages { |msg| puts "#{msg.body} #{msg.type}" }
>
> im.disconnect
>
> ---
>
> ochomo

--
Posted via http://www.ruby-....

Veera Sundaravel

10/15/2008 6:33:00 AM

0

Zablon Ochomo wrote:
> The code below is working with the xmpp4r form
> http://home.gna.o...
>
> require 'XMPP4R'
> begin
> # Connect to the server and set presence to available for chat.
> jid = Jabber::JID.new('myjid@xmppserver/Resource')
> client = Jabber::Client.new(jid, false)
> client.connect
> client.auth('passwd')
> client.send(Jabber::Presence.new.set_show(:chat).set_status('Ruby!'))
>
> # Send an Instant Message.
> body = 'Hi XMPP'
> to_jid = Jabber::JID.new('tojid@xmppserver')
> message = Jabber::Message::new(to_jid,
> body).set_type(:normal).set_id('1')
> client.send(message)
> end
>
> question:
>
> how do I receive messages, since I can only send?
>
> ---
> ochomo

Hi Zablon,

I can send IM to only by setting presence status, But my account have
more than 50 or 100 contacts. It will take long time to set the presence
and getting status message from each contact.

ie,
client.send(Jabber::Presence.new.set_show(:chat).set_status('Ruby!'))
line of code breaks the functionality of client.send(message).

Setting presence took long time, but before to that send message code
executed. If I have to wait for getting result of setting presence and
then running the send message code only results the required output.

Is there any way to send IM without setting Presence.

My sever installed with Openfire and IM gateway plugin. Whether I have
to install any other plugin or source to automatically log into
Transport.

Please give your valuable suggestion.

Regards,
T.Veeraa.


--
Posted via http://www.ruby-....

Zablon Ochomo

10/15/2008 6:44:00 AM

0

Veera,
I was only trying out on this code. I didnt go much deep.

I was trying to find a way of communicating between my software modules.
I decided to use ISO 8583 protocol instead.

Sorry, I wish I could help.

Ochomo

Veera Sundaravel wrote:
> Zablon Ochomo wrote:
>> The code below is working with the xmpp4r form
>> http://home.gna.o...
>>
>> require 'XMPP4R'
>> begin
>> # Connect to the server and set presence to available for chat.
>> jid = Jabber::JID.new('myjid@xmppserver/Resource')
>> client = Jabber::Client.new(jid, false)
>> client.connect
>> client.auth('passwd')
>> client.send(Jabber::Presence.new.set_show(:chat).set_status('Ruby!'))
>>
>> # Send an Instant Message.
>> body = 'Hi XMPP'
>> to_jid = Jabber::JID.new('tojid@xmppserver')
>> message = Jabber::Message::new(to_jid,
>> body).set_type(:normal).set_id('1')
>> client.send(message)
>> end
>>
>> question:
>>
>> how do I receive messages, since I can only send?
>>
>> ---
>> ochomo
>
> Hi Zablon,
>
> I can send IM to only by setting presence status, But my account have
> more than 50 or 100 contacts. It will take long time to set the presence
> and getting status message from each contact.
>
> ie,
> client.send(Jabber::Presence.new.set_show(:chat).set_status('Ruby!'))
> line of code breaks the functionality of client.send(message).
>
> Setting presence took long time, but before to that send message code
> executed. If I have to wait for getting result of setting presence and
> then running the send message code only results the required output.
>
> Is there any way to send IM without setting Presence.
>
> My sever installed with Openfire and IM gateway plugin. Whether I have
> to install any other plugin or source to automatically log into
> Transport.
>
> Please give your valuable suggestion.
>
> Regards,
> T.Veeraa.

--
Posted via http://www.ruby-....

Veera Sundaravel

10/15/2008 10:45:00 AM

0

Hi Zablon,

No problem, thanks for instant reply. If I can solve the issue, I'l keep
you posted.

Regards,
T.Veeraa.
--
Posted via http://www.ruby-....