Exchange Object/Class data between Java and C++

1.2k views Asked by At

I need to pass data between c++ program and a Java GUI that is showing that data. I can put that data in a class but the c++ program could be running on linux(raspberry pie) and java may or may not be on windows. What options do i have? Kindly help me for same machine processes and also if they are on different machines. P.S. On different machines internet connection is available.

1

There are 1 answers

1
Basile Starynkevitch On

You may want to implement some serialization.

I suggest using a simple textual serialization format like JSON (but you might consider also YAML or even XML). There are many JSON libraries available, like jansson (in C), JsonCpp (in C++) and several for Java.

Of course, you need some form of Inter-Process Communication. This can be sockets or pipes. Read e.g. Advanced Linux Programming or some other tutorial. Maybe have some Event Loop (e.g. libev, libevent) or even use JSON-RPC (or perhaps some HTTP server library)

You could use binary serialization like XDR or using libs11n but it is usually not worth the trouble.