[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Communication between 2 ruby programs

Julien Genestoux

7/10/2008 9:53:00 PM

Hi!

I am having a hard time solving this issue and I'm sure you guys know
how to treat that very easily!

I've got a "bot" on one side which runs :

class Bot

def self.start
loop do
input = gets # Get a user input from STDIN
# do some stuff with the input!
end
end

Bot:start

end

And on the other side, I've got a Rails application. I want to "plug"
the bot to this rails application, in such a way that the inputs are
coming from the Rails application, and not from STDIN.

I guess that it doesn't change anything that my "client" is a rails app,
but I mentionned it in case it's bad in any way ;-) Also, the
communication is just "one-way"; there is no need for the bot to return
anything to the client!

Any idea on how to solve this?

You're help would be greatly appreciated!

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

7 Answers

James Britt

7/10/2008 11:18:00 PM

0

Julien Genestoux wrote:
> Hi!
>
> I am having a hard time solving this issue and I'm sure you guys know
> how to treat that very easily!
>
> I've got a "bot" on one side which runs :
>
...

>
> And on the other side, I've got a Rails application. I want to "plug"
> the bot to this rails application, in such a way that the inputs are
> coming from the Rails application, and not from STDIN.
>


Have you considered using xml-rpc? Ruby includes a library for that.

It has its pros and cons, but overall it may be good enough.

--
James Britt

www.happycamperstudios.com - Wicked Cool Coding
www.jamesbritt.com - Playing with Better Toys
www.ruby-doc.org - Ruby Help & Documentation
www.rubystuff.com - The Ruby Store for Ruby Stuff

Julien Genestoux

7/10/2008 11:23:00 PM

0

Hum,

Both applications are on the same machine, so I am not sure I need to go
over the network with XML RPC, I would lose a lot performance wise,
don't you think?

Initially, I tried with Pipes, but I could not find my way with this...

Thanks for your help, anyway.

Anyone else?


James Britt wrote:
> Julien Genestoux wrote:
>> Hi!
>>
>> I am having a hard time solving this issue and I'm sure you guys know
>> how to treat that very easily!
>>
>> I've got a "bot" on one side which runs :
>>
> ...
>
>>
>> And on the other side, I've got a Rails application. I want to "plug"
>> the bot to this rails application, in such a way that the inputs are
>> coming from the Rails application, and not from STDIN.
>>
>
>
> Have you considered using xml-rpc? Ruby includes a library for that.
>
> It has its pros and cons, but overall it may be good enough.
>
> --
> James Britt
>
> www.happycamperstudios.com - Wicked Cool Coding
> www.jamesbritt.com - Playing with Better Toys
> www.ruby-doc.org - Ruby Help & Documentation
> www.rubystuff.com - The Ruby Store for Ruby Stuff

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

ara.t.howard

7/10/2008 11:23:00 PM

0


On Jul 10, 2008, at 3:52 PM, Julien Genestoux wrote:

> And on the other side, I've got a Rails application. I want to "plug"
> the bot to this rails application, in such a way that the inputs are
> coming from the Rails application, and not from STDIN.



bot = IO.popen 'bot.rb', 'r+'


bot.puts 'some command'
bot.flush


a @ http://codeforp...
--
we can deny everything, except that we have the possibility of being
better. simply reflect on that.
h.h. the 14th dalai lama




Julien Genestoux

7/11/2008 12:22:00 AM

0

Correct me if I'm wrong, but popen will "fork" the current process and
run bot.rb in the child.

Actually, here, the bot is already "running" and doing some "other
stuff" that do not require inputs!

Thanks anyway!


ara.t.howard wrote:
> On Jul 10, 2008, at 3:52 PM, Julien Genestoux wrote:
>
>> And on the other side, I've got a Rails application. I want to "plug"
>> the bot to this rails application, in such a way that the inputs are
>> coming from the Rails application, and not from STDIN.
>
>
>
> bot = IO.popen 'bot.rb', 'r+'
>
>
> bot.puts 'some command'
> bot.flush
>
>
> a @ http://codeforp...

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

Eric Hodel

7/11/2008 12:30:00 AM

0

On Jul 10, 2008, at 14:52 PM, Julien Genestoux wrote:

> I am having a hard time solving this issue and I'm sure you guys know
> how to treat that very easily!
>
> I've got a "bot" on one side which runs :
>
> class Bot
>
> def self.start
> loop do
> input = gets # Get a user input from STDIN
> # do some stuff with the input!
> end
> end
>
> Bot:start
>
> end
>
> And on the other side, I've got a Rails application. I want to "plug"
> the bot to this rails application, in such a way that the inputs are
> coming from the Rails application, and not from STDIN.
>
> I guess that it doesn't change anything that my "client" is a rails
> app,
> but I mentionned it in case it's bad in any way ;-) Also, the
> communication is just "one-way"; there is no need for the bot to
> return
> anything to the client!
>
> Any idea on how to solve this?

The RailsRemoteControl gem may be a good start.

ara.t.howard

7/11/2008 3:42:00 AM

0


On Jul 10, 2008, at 6:21 PM, Julien Genestoux wrote:

> Correct me if I'm wrong, but popen will "fork" the current process and
> run bot.rb in the child.
>
> Actually, here, the bot is already "running" and doing some "other
> stuff" that do not require inputs!
>
> Thanks anyway!


man mkfifo



a @ http://codeforp...
--
we can deny everything, except that we have the possibility of being
better. simply reflect on that.
h.h. the 14th dalai lama




mail list

7/11/2008 5:04:00 AM

0

I would look at activemessaging plugin for this if you want something
scalable...
http://code.google.com/p/activemessaging/wiki/Activ...

It also is pretty simple to send jms message using jruby to the rails
app. I have a bunch of rails apps communicating to servers using jms
and it is robust and scalable. But this code is not very pretty.

http://rubyforge.org/projects/sto...


S.
On Jul 11, 2008, at 5:52 AM, Julien Genestoux wrote:

> Hi!
>
> I am having a hard time solving this issue and I'm sure you guys know
> how to treat that very easily!
>
> I've got a "bot" on one side which runs :
>
> class Bot
>
> def self.start
> loop do
> input = gets # Get a user input from STDIN
> # do some stuff with the input!
> end
> end
>
> Bot:start
>
> end
>
> And on the other side, I've got a Rails application. I want to "plug"
> the bot to this rails application, in such a way that the inputs are
> coming from the Rails application, and not from STDIN.
>
> I guess that it doesn't change anything that my "client" is a rails
> app,
> but I mentionned it in case it's bad in any way ;-) Also, the
> communication is just "one-way"; there is no need for the bot to
> return
> anything to the client!
>
> Any idea on how to solve this?
>
> You're help would be greatly appreciated!
>
> Julien
> --
> Posted via http://www.ruby-....
>