Simple Instant Messenger (Gtalk) in ruby

Wow, when i came to see about gem “xmpp4r-simple” , I was shocked .

It was very simple code which will create an Instant Messenger .

Installation : is very simple ( for ubuntu )

sudo gem install xmpp4r-simple

Then just small piece of code :)
 require 'rubygems'  
 require 'xmpp4r-simple'  

 username = 'sathia2704'  
 password = '******'
 to_username = 'noreplybysathia'  

 puts "Connecting to jabber server.."  
 jabber ='',password)  
 puts "Connected."  
 jabber.deliver(to_username+"", "Hello..!")
 while (true) do  
         jabber.received_messages do |msg|  
                 puts "=============================================="  
                 puts msg.body  
                 puts "----------------------------------------------"
                 jabber.deliver(msg.from.node+"", msg.body)  


This code will send message and recieve message . I will soon

integrate this with rails app 🙂

Some sceenshots:

This slideshow requires JavaScript.

and for PHP


// activate full error reporting
//error_reporting(E_ALL & E_STRICT);

include 'XMPP.php';

#Use XMPPHP_Log::LEVEL_VERBOSE to get more logging for error reports
#If this doesn't work, are you running 64-bit PHP with < 5.2.6?
$conn = new XMPPHP_XMPP('', 5222, '', 'sathia44', 'xmpphp', '', $printlog=false, $loglevel=XMPPHP_Log::LEVEL_INFO);

try {
    $conn->message('', 'Hi machi');
} catch(XMPPHP_Exception $e) {

Note : XMpp.php you have to download . form
and also documentation and examples are available.

Above code PHP is only for sending message and not for receiving



About sathia

Web developer at cloudmint
This entry was posted in programs and tagged , , , , , , , , , , , . Bookmark the permalink.

12 Responses to Simple Instant Messenger (Gtalk) in ruby

  1. Ramachandran says:

    Great. Nice Post.:)
    Thanks for sharing…

  2. Arulalan.T says:

    Really Superb….

    Keep Rocking……

  3. rajee says:

    Me too surprised to see this type of application using Ruby.
    Good post sathia
    Thanks 🙂

  4. sathia27 says:

    thank u for all 🙂

  5. patrick says:

    its not working. when i run the ruby chat it display only
    Connecting to jabber server..

    • sathia says:

      Hi patrick,
      Have you given correct username and password of yours.. Please check the following . only give username of ur mail id like “sathia2704”, not as “”..

      or Please show me your code if you fif not get output..

      Thank you .

  6. thiru says:

    It’s working fine.
    I need to use this method for chat process.Is this possible?
    Please reply.

  7. thiru says:

    Hi ,

    What I am asking how do i send an INVITATION to chat in XMPPHP.

  8. vijay rathod says:

    nice code like it and useful… thanks
    but i need receive code if possible thanks in advance .. reply as soon as possible … thanks…

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s