Communication between C++ server and Python app

classic Classic list List threaded Threaded
13 messages Options
Reply | Threaded
Open this post in threaded view
|

Communication between C++ server and Python app

kenk
Hi,

I've got a server process written in C++ running on Unix machine.
On the same box I'd like to run multiple Python scripts that will
communicate with this server.

Can you please suggest what would be best was to achieve this ?

Kind regards and thanks in advance!
M.
--
http://mail.python.org/mailman/listinfo/python-list
Reply | Threaded
Open this post in threaded view
|

Re: Communication between C++ server and Python app

Chris Angelico
On Sun, Apr 29, 2012 at 10:45 AM, kenk <[hidden email]> wrote:
> Hi,
>
> I've got a server process written in C++ running on Unix machine.
> On the same box I'd like to run multiple Python scripts that will
> communicate with this server.
>
> Can you please suggest what would be best was to achieve this ?

Personally, I would recommend a TCP socket, because that allows the
flexibility of splitting across multiple computers. But for
efficiency, you may want to consider a Unix socket too.

ChrisA
--
http://mail.python.org/mailman/listinfo/python-list
Reply | Threaded
Open this post in threaded view
|

Re: Communication between C++ server and Python app

Roy Smith
In reply to this post by kenk
In article
<[hidden email]>,
 kenk <[hidden email]> wrote:

> Hi,
>
> I've got a server process written in C++ running on Unix machine.
> On the same box I'd like to run multiple Python scripts that will
> communicate with this server.
>
> Can you please suggest what would be best was to achieve this ?

There are so many reasonable answers, it's hard to know where to start.  
Perhaps if you could give us some clue as to what the server does, it
might help.

What kind of data are you passing back and forth?  Text?  Binary?  Is it
important that the communication be as efficient as possible, or is it
more important that the code be easy to write?  Are you worried about
security?  Will you ever need to interoperate with other systems written
in other languages?
--
http://mail.python.org/mailman/listinfo/python-list
Reply | Threaded
Open this post in threaded view
|

Re: Communication between C++ server and Python app

Rodrick Brown
In reply to this post by kenk
What interfaces are available on the server process?

Sent from my iPad

On Apr 28, 2012, at 8:45 PM, kenk <[hidden email]> wrote:

> Hi,
>
> I've got a server process written in C++ running on Unix machine.
> On the same box I'd like to run multiple Python scripts that will
> communicate with this server.
>
> Can you please suggest what would be best was to achieve this ?
>
> Kind regards and thanks in advance!
> M.
> --
> http://mail.python.org/mailman/listinfo/python-list
--
http://mail.python.org/mailman/listinfo/python-list
Reply | Threaded
Open this post in threaded view
|

Re: Communication between C++ server and Python app

Cameron Simpson
In reply to this post by Chris Angelico
On 29Apr2012 11:42, Chris Angelico <[hidden email]> wrote:
| On Sun, Apr 29, 2012 at 10:45 AM, kenk <[hidden email]> wrote:
| > I've got a server process written in C++ running on Unix machine.
| > On the same box I'd like to run multiple Python scripts that will
| > communicate with this server.
| >
| > Can you please suggest what would be best was to achieve this ?
|
| Personally, I would recommend a TCP socket, because that allows the
| flexibility of splitting across multiple computers.

And the pain of ensuring security, if you're in an open network.

| But for
| efficiency, you may want to consider a Unix socket too.

A UNIX socket or even a named pipe has the benefit of:
  - not being available remotely
  - access control with normal UNIX permissions
and of course efficiency as you say.

Generalising to a TCP socket later shouldn't be too hard if the need
arises.

Cheers,
--
Cameron Simpson <[hidden email]> DoD#743
http://www.cskk.ezoshosting.com/cs/

Waiting for the bus is a bad idea if you turn out to be the bus driver.
- Michael M. Butler on the Singularity
--
http://mail.python.org/mailman/listinfo/python-list
Reply | Threaded
Open this post in threaded view
|

Re: Communication between C++ server and Python app

Tamer Higazi
Take the twisted library.
I used to write myself a socket server and client.

Socket is fast, but you need on the other hand to know how big the
dataset might be, that will be serialized and deserialized as well.



Tamer

Am 29.04.2012 08:24, schrieb Cameron Simpson:

> On 29Apr2012 11:42, Chris Angelico <[hidden email]> wrote:
> | On Sun, Apr 29, 2012 at 10:45 AM, kenk <[hidden email]> wrote:
> | > I've got a server process written in C++ running on Unix machine.
> | > On the same box I'd like to run multiple Python scripts that will
> | > communicate with this server.
> | >
> | > Can you please suggest what would be best was to achieve this ?
> |
> | Personally, I would recommend a TCP socket, because that allows the
> | flexibility of splitting across multiple computers.
>
> And the pain of ensuring security, if you're in an open network.
>
> | But for
> | efficiency, you may want to consider a Unix socket too.
>
> A UNIX socket or even a named pipe has the benefit of:
>   - not being available remotely
>   - access control with normal UNIX permissions
> and of course efficiency as you say.
>
> Generalising to a TCP socket later shouldn't be too hard if the need
> arises.
>
> Cheers,

--
http://mail.python.org/mailman/listinfo/python-list
Reply | Threaded
Open this post in threaded view
|

Re: Communication between C++ server and Python app

Chris Angelico
In reply to this post by Cameron Simpson
On Sun, Apr 29, 2012 at 4:24 PM, Cameron Simpson <[hidden email]> wrote:
> On 29Apr2012 11:42, Chris Angelico <[hidden email]> wrote:
> | Personally, I would recommend a TCP socket, because that allows the
> | flexibility of splitting across multiple computers.
>
> And the pain of ensuring security, if you're in an open network.

You have that with all IPC. You can always bind to 127.0.0.1 or ::1 to
stop other hosts from connecting; and then it's minimal change to open
it up.

ChrisA
--
http://mail.python.org/mailman/listinfo/python-list
Reply | Threaded
Open this post in threaded view
|

Re: Communication between C++ server and Python app

kenk
In reply to this post by Rodrick Brown
Failr point  - I should do that in original question.

The C++ server runs on Unix (Mac OS X as a matter of fact) and, as I'm the one who develops it, can use whthever technology is suitable. 
Currently it uses STL, Boost and Qt libraries.

The server is responsible for providing connectivity to stock exchange and will be used mainly to monitor price of certain financial instruments and placing/cancelling orders.
My idea is to keep this as simple tool that will execute whathever it's asked for.

On top of this server I plan to write some trading logic in Python - scripts that will trigger certain actions depending on situation on market.

I planned to exchange text commands between the C++ server and Python scripts as Python is really good in parsing text and on server side Boost/STL also do the trick.
Communication between 'logic' and the server won't be high frequency - I plan to talk to teh server ~10 times a minute.

Will appreciate suggestions.

M.



On 29 Apr 2012, at 05:00, Rodrick Brown wrote:

Sent from my iPad

On Apr 28, 2012, at 8:45 PM, kenk <[hidden email]> wrote:

Hi,

I've got a server process written in C++ running on Unix machine.
On the same box I'd like to run multiple Python scripts that will
communicate with this server.

Can you please suggest what would be best was to achieve this ?

Kind regards and thanks in advance!
M.
--
http://mail.python.org/mailman/listinfo/python-list


--
http://mail.python.org/mailman/listinfo/python-list
Reply | Threaded
Open this post in threaded view
|

Re: Communication between C++ server and Python app

Cameron Simpson
In reply to this post by Chris Angelico
On 29Apr2012 21:08, Chris Angelico <[hidden email]> wrote:
| On Sun, Apr 29, 2012 at 4:24 PM, Cameron Simpson <[hidden email]> wrote:
| > On 29Apr2012 11:42, Chris Angelico <[hidden email]> wrote:
| > | Personally, I would recommend a TCP socket, because that allows the
| > | flexibility of splitting across multiple computers.
| >
| > And the pain of ensuring security, if you're in an open network.
|
| You have that with all IPC. You can always bind to 127.0.0.1 or ::1 to
| stop other hosts from connecting; and then it's minimal change to open
| it up.

I'm as concerned with other users as with other hosts. Hence the pleasures of
UNIX permissions on a socket. You're right, I did say "open network", didn't
I? Nonetheless, my preference stands unless a new use case arises.

Cheers,
--
Cameron Simpson <[hidden email]> DoD#743
http://www.cskk.ezoshosting.com/cs/

Just because Unix is a multiuser system doesn't mean I want to share it with
anybody!        - Paul Tomblin, in rec.aviation.military
--
http://mail.python.org/mailman/listinfo/python-list
Reply | Threaded
Open this post in threaded view
|

Re: Communication between C++ server and Python app

kenk
In reply to this post by Roy Smith
Failr point  - I should do that in original question.

The C++ server runs on Unix (Mac OS X as a matter of fact) and, as I'm
the one who develops it, can use whthever technology is suitable.
Currently it uses STL, Boost and Qt libraries.

The server is responsible for providing connectivity to stock exchange
and will be used mainly to monitor price of certain financial
instruments and placing/cancelling orders.
My idea is to keep this as simple tool that will execute whathever
it's asked for.

On top of this server I plan to write some trading logic in Python -
scripts that will trigger certain actions depending on situation on
market.

I planned to exchange text commands between the C++ server and Python
scripts as Python is really good in parsing text and on server side
Boost/STL also do the trick.
Communication between 'logic' and the server won't be high frequency -
I plan to talk to teh server ~10 times a minute.

Will appreciate suggestions.

M.
--
http://mail.python.org/mailman/listinfo/python-list
Reply | Threaded
Open this post in threaded view
|

Re: Communication between C++ server and Python app

Miki Tebeka-4
In reply to this post by Roy Smith
> > I've got a server process written in C++ running on Unix machine.
> > On the same box I'd like to run multiple Python scripts that will
> > communicate with this server.
> >
> > Can you please suggest what would be best was to achieve this ?
As said before, there are many options. Here are some:
* protobuf, thrift, avro ...
* json/xml over http
   - Python has XMLRPC module
* zeromq
* ...

IMO investigate some time learning the options, code a simple api using one or two that you like and pick a winner.

For 10 calls/min you can go that wrong either way :)
--
http://mail.python.org/mailman/listinfo/python-list
Reply | Threaded
Open this post in threaded view
|

Re: Communication between C++ server and Python app

Adam Tauno Williams
In reply to this post by kenk
On Sat, 2012-04-28 at 17:45 -0700, kenk wrote:
> I've got a server process written in C++ running on Unix machine.
> On the same box I'd like to run multiple Python scripts that will
> communicate with this server.
> Can you please suggest what would be best was to achieve this ?

Time to start using a message broker that can also grow to other
applications.

RabbitMQ.  Simple, fast, and easy to manage.
<http://www.rabbitmq.com/>

This allows each service to have outages without loosing information.

--
http://mail.python.org/mailman/listinfo/python-list

signature.asc (205 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Communication between C++ server and Python app

premiumtelco
Banned User
In reply to this post by kenk
I normally wouldn?t be able to find such great content as this on other
sites. You have done a great job with each unique point made on this topic.
Thank you for your hard work.





-----
premium rate numbers
Click Here
premiumtelco
--
View this message in context: http://python.6.n6.nabble.com/Communication-between-C-server-and-Python-app-tp4937660p5011431.html
Sent from the Python - python-list mailing list archive at Nabble.com.