Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Ruby (http://www.velocityreviews.com/forums/f66-ruby.html)
-   -   Interprocess communication (http://www.velocityreviews.com/forums/t822909-interprocess-communication.html)

Jonas Galvez 07-12-2005 09:19 AM

Interprocess communication
 
I have a Python script running as daemon. I need a way to have a Ruby
script send a message to it and read a response. I've been reading
about pipes and fifo but it's all very confusing.

Just thought I'd ask before trying anything: what's the safest and
easiest way to accomplish this in Ruby?

--Jonas Galvez



Robert Klemme 07-12-2005 09:26 AM

Re: Interprocess communication
 
Jonas Galvez wrote:
> I have a Python script running as daemon. I need a way to have a Ruby
> script send a message to it and read a response. I've been reading
> about pipes and fifo but it's all very confusing.
>
> Just thought I'd ask before trying anything: what's the safest and
> easiest way to accomplish this in Ruby?


Depends on which changes you can do to the python script. Does it offer
some kind of messaging functionality already?

If you can start from scratch (for example because you have to change the
phython script anyway) you can do any of these:

- make the python script open a pair of named pipes, one for reading and
one for writing answers. This works good only if you do have just a
single client (your ruby script)

- make the phython script open a unix domain socket (which is accessible
only from localhost). That way you can have several clients connect but
your phython script must handle these.

- dedicate a directory for exchange of messages via files. You then need
some kind of locking and a protocol, who writes which files there etc.

It really depends on your situation and requirements. If you provide more
input we might be able to come up with a more concrete suggestion.

Kind regards

robert


Dido Sevilla 07-12-2005 11:51 PM

Re: Interprocess communication
 
On 7/12/05, Jonas Galvez <jonasgalvez@gmail.com> wrote:
> I have a Python script running as daemon. I need a way to have a Ruby
> script send a message to it and read a response. I've been reading
> about pipes and fifo but it's all very confusing.
>=20
> Just thought I'd ask before trying anything: what's the safest and
> easiest way to accomplish this in Ruby?


The simplest (not necessarily the best, that would on your
application's exact requirements, of which you've given us few
details), I think, would be to use XML-RPC. There are mature and
well-tested XML-RPC libraries for both Ruby and Python (for Python, I
believe it's integrated into the language's standard libraries
already). Set your Python script to be an XML-RPC server, and Ruby to
be your XML-RPC client and off you go. This ought to work even if your
Ruby and Python scripts are running on different computers, but it's a
fairly heavyweight approach.



Lyndon Samson 07-13-2005 12:04 AM

Re: Interprocess communication
 
> The simplest (not necessarily the best, that would on your
> application's exact requirements, of which you've given us few
> details), I think, would be to use XML-RPC. There are mature and
> well-tested XML-RPC libraries for both Ruby and Python (for Python, I
> believe it's integrated into the language's standard libraries
> already). Set your Python script to be an XML-RPC server, and Ruby to
> be your XML-RPC client and off you go. This ought to work even if your
> Ruby and Python scripts are running on different computers, but it's a
> fairly heavyweight approach.
>=20


You could of course use the principles of OO and abstract that away,
perhaps providing a shared memory impl as well as the XML-RPC.




--=20
Into RFID? www.rfidnewsupdate.com Simple, fast, news.




All times are GMT. The time now is 04:47 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.