Reputation: 57
Please tell me how to serialize data (like binary files) in C. And, how can i send this serialized data over sockets, so that it can be successfully received by the corresponding Java client.
Actually i want to convert this binary file into byte array so that it can be send over the sockets.
Thanks in advance.
Upvotes: 3
Views: 1960
Reputation: 3309
Both send()/recv() in C and java.lang.Socket operate seamlessly on byte arrays. So, if everything you need is just sending plain byte arrays, without any structure-specific encoding, you don't really need any serialization.
Upvotes: 0
Reputation: 2197
Have you considered using a communication format such as JSON instead of raw byte RPC
For information on libraries which provide JSON for C & Java (More are available on the JSON site)
The advantages of using JSON include:
JSON would be ideal in the case that you need to transmit object instances. If however you are truly dealing with flat binary files (that are not serialized objects) then Protocol Buffers by Google as suggested by caf will most likely be better suited (especially if they are large files).
NB: JSON requires that your byte content be encoded into a BASE64 string for transfer.
Upvotes: 2
Reputation: 239071
For interoperating between C and Java, you could use Google's Protocol Buffers (the Google reference implementation supports C++ and Java, and there's third party implementations for plain C).
Upvotes: 3