I need to be able to communicate between two applications that reside on the same machine. One is using Flex and the other is in C++. I would like to be able to call functions and pass arguments to each other. What is the best way to communicate between them? I was thinking about using sockets.
As for now yes, you'll need to use sockets.
AIR 2.0 will provide access to native processes, but that will require a native (per OS) installer. More info: http://www.mikechambers.com/blog/2009/09/22/fotb-slides-advanced-desktop-development-with-adobe-air/
As for AIR 1.x, Mike Chambers posted a sample library called CommandProxy which does the trick. It provides code for AS3 and .NET which could easily be ported to C++ if you have a decent XML parser.
The basic idea is that each compnent can send each other XML "packets" across the wire where each one has an ID to ensure the request/response can be tied together. However, both the AS3 and .NET code don't account for slow or fast TCP/IP speeds where two XML chunks could be sent on one packet or one XML chunk split across two. Any ways, it does the trick.
Also, you could look for a C++ AMF (ActionScript Message Format) library so that you could serialize AS3 objects over the wire which would have a more "integrated" feel.
Related
I'm working on a project that will include a server and a client component that will send/receive requests / information over TCP/IP. The server component will be developed in c++ and I will be using boost.asio libraries. Client component will be an excel add-in and will be developed in visual basic. I have few general questions and please note that I'm not expecting any specific response here but expecting to hear some concepts so I can focus on.
My questions are as below.
The server and the client will be developed in different languages, is there anything to worry about socket communication between two developing languages?
I want the application to have login/authentication mechanism through integration with LDAP systems. Is there any c++ libraries that I can use for this purpose? (like boost.asio for TCP)
Is there any concept that you can suggest user session management in c++
As part of my application, there will be need to transfer data from the server to the client or vice versa. This data can sometime be like hundreds to thousands rows with hundred of columns. What is the best way to transfer such data through sockets? Is arrays good for this?
I know my questions are very high level and basic but your answers will point me the right direction and will help me to focus on the right concepts.
Thanks in advance.
The server and the client will be developed in different languages, is there anything to worry about socket communication between two developing languages?
Not really, as long as you have a clearly defined wire format. Either use an existing one, like HTTP/JSON, or define it yourself explicitly. When the interface is a bit more complicated, consider to use something like CORBA or ICE.
I want the application to have login/authentication mechanism through integration with LDAP systems. Is there any c++ libraries that I can use for this purpose? (like boost.asio for TCP)
There is a C++ API for OpenLDAP. I have no experience with it, so no recommendation or warning here.
Is there any concept that you can suggest user session management in c++
It depends on what you need. The easiest approach is a vector of shared pointers to session objects ordered by age, but those sessions will all be invalid when the process ist restarted. Sessions in memcached survive a restart of the process. When you want to survive the restart of a machine, I'd prefer the session data in a relational database, or files.
As part of my application, there will be need to transfer data from the server to the client or vice versa. This data can sometime be like hundreds to thousands rows with hundred of columns. What is the best way to transfer such data through sockets? Is arrays good for this?
You might use a simple format for each object and simply stream the objects. E.g. CSV, or JSON. Also consider a binary fixed format, when most of your information is not already text. What is the best depends on the type of data, of course.
I am building a server-client application that involves heavy signal processing (e.g. FFT). I have a working application written in C++/Qt, where everything (signal processing and other calculations) is done in client and server just sends raw data. Now I feel it would be easier to implement these features on the server. So, that maintenance becomes easier.
As I am doing signal processing, I think I should stick to C++ for performance. But I am open to new ideas.
Constraints:
I need type checking so javascript is out of discussion.
Scaling includes adding more server and each server will have at the max
10-12 users. So, Hardware cost is important. I cannot use x number of
i7 processors.
No option of using cloud services.
So, right now my question is as follows:
How can I create web services using C++ for Linux server? (Although cross platform is not important, I would appreciate if I can achieve it.)
EDIT [02:09:2015]
Right now, I think the choice is between poco and C++ Rest SDK. I feel I should go for C++ Rest SDK. Mainly because it has only those features that I need. And Also it is supported by microsoft and uses boost internally. So, I feel in future, this might be well integreated with standard.
You could use cross-platform Poco library to implement HTTP server, it is really straightforward with this framework, and they have a lot of examples. You can also use JSON serialization (like rapidjson library) to implement REST service on top of HTTP - this way your Web service will be accesable by most of the modern Web frameworks.
You might want to take a look at the C++ Rest SDK, an open source, cross platform API from Microsoft.
Like #nogard suggested, I also recommend POCO for now. It's the most serious and feature-full solution. Given you mentioned Qt, I suggest you to take a look at Tufão.
EDIT:
I forgot to mention one comparison of mine on the C++ HTTP server frameworks.
If you directly handle HTTP requests, you might loose the functionality what Web Servers does well what it was build to do. I had a similar issue, what I did was wrap up my Qt c++ code inside a PHP extension. In your case you can do the same. Wrap your logic inside what ever technology you are about to use, doesn't matter it's PHP, net , Java or anything else.
I'm aware there is no official C++ library for Parse (https://parse.com). I've got a desktop variant of an app written using Qt C++ for OSX/Windows that needs to talk to Parse. I'm embarking on writing my own client for the Parse REST API based on the PHP library (https://github.com/apotropaic/parse.com-php-library) and the Qt network classes. Would you recommend a different approach?
The data I am saving is pretty basic, some objects and some geo data, but it would be nice to have a general solution to share with others. I will happily release whatever I come up with via GitHub, and all the better if this can lead to a group of us sharing the load.
Cheers!
How or what do I need to know programming wise in order to interact with the web using c++. For instance i want to wrote a program that automatically sends invites to players on yahoo chess. How would i go about doing this?
You'll need to understand the basics of TCP/IP and HTTP, possibly UDP, and the protocols involved with Yahoo's chess systems or posses a tool to work around them (A brief search leads me to believe there are few if any). You'll probably need a network API, I'd suggest looking at:
QtNetwork Module
Boost.Asio
Where Qt is easy to use, Asio is more powerful, and more 'C++' in nature. Qt has some nice webkit components, and I've used it to build a small web server, which was a lot of fun. You can accomplish quite a lot with it.
This page says they've added a captcha system to prevent certain people from interacting with their systems. I'm not familiar with Yahoo games and what the result of this has on what you'd want to do, however it suggests to me they'd rather you didn't write code to interact with their systems.
For this you need to use network APIs and use server side script like PHP/ASP to communicate with the web and C using message queue.
I have a C++ process running in the background that will be generating 'events' infrequently that a Python process running on the same box will need to pick up.
The code on the C side needs to be as lightweight as possible.
The Python side is read-only.
The implementation must be cross-platform.
The data being sent is very simple.
What are my options?
Thanks
zeromq -- and nothing else. encode the messages as strings.
However, If you want to get serialiazation from a library use protobuf it will generate classes for Python and C++. You use the SerializeToString() and ParseFromString() functions on either end, and then pipe the strings via ZeroMq.
Problem solved, as I doubt any other solution is faster, and neither will any other solution be as easy to wire-up and simple to understand.
If want to use specific system primitives for rpc such as named pipes on Windows and Unix Domain Sockets on unix then you should look at Boost::ASIO. However, unless you have (a) a networking background, and (b) a very good understanding of C++, this will be very time consuming
Use zeromq, it's about as simple as you can get.
Google's protobuf is a great library for RPC between programs. It generates bindings for Python and C++.
If you need a distributed messaging system, you could also use something like RabbitMQ, zeromq, or ActiveMQ. See this question for a discussion on the message queue libraries.
Another option is to just call your C code from your Python code using the ctypes module rather than running the two programs separately.
How complex is your data? If it is simple I would serialize it as a string. If it was moderately complex I would use JSON. TCP is a good cross-platform IPC transport. Since you say that this IPC is rare the performance isn't very important, and TCP+JSON will be fine.
You can use Google GRPC for this
I will say you create a DLL that will manage the communication between the two. The python will load DLL and call method like getData() and the DLL will in turn communicate with process and get the data.
That should not be hard.
Also you can use XML file or SQLite database or any database to query data. The daemon will update DB and Python will keep querying. There might be a filed for indicating if the data in DB is already updated by daemon and then Python will query.
Of course it depends on performance and accuracy factors!