简体   繁体   中英

Commucation Between C++ Client and Java Server

I'm developing a Client application which talks to a Server using HTTP. The Client is in C++ and the Server component is in J2EE. I'm able to exchange data between Client and Server successfully. Now I want to encapsulate pices of information in a C++ object in client and send it in the HTTP request to server. My server after receiving the data should deserialize the C++ object to a java object.

My question is, I want to know whether we can exchange an object in the above mentioned way and if it can be achieved, could someone help me by providing references to online tutorials or code sample?

You need to serialize the object into XML, JSON or something like that.

You can't use technology-specific serialization (eg RMI for java) because you are working cross stack (and it's bad practice anyway).

Don't know about c++ but in java binding objects to XML/JSON is trivial using JAXB. If you are exposing a webservice you can go the easy way: REST (using JAX-RS) or the slightly harder but technically better way (in that it has more features): SOAP (using JAX-WS).

Exposing such webservices is trivial in Java EE if you read up on the relevant webservice stacks.

It would be a nightmare if you send plain old C++ objects to the Server. You need to have a common protocol between client and server. A good option for this is JSON. The flow would be like this:

C++ object -> serialize to -> JSON -> deserialize to -> Java object

To serialize C++ objects into JSON using something like JSON Spirit . To deserialize the JSON into Java objects, Gson is a safe bet (it even does the conversion on-the-fly). You can find documentation for both projects on their respective homepages.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM