I'm implementing a server push via a socket connection to an Objective-C based application. I'm at the point where I'm sending my data through an outputstream on the socket but I need to reassemble the data on the Objective-c end. At this point I haven't even looked at the objective-c IO classes and I am wondering how can I ensure maximum compatibility on the java end? I'm guessing I have to stick to primitive datatypes, am I going to have any problems getting back Strings that I stick into the outputStream? Most of what I'm sending will be strings that are more or less xml snippets/documents so if there's a better way to do this let me know! Keep in mind that my interaction on the socket is purely one-way. All the user-updating of my application occurs via standard Servlet interaction.
2 Answers
If you are open to using a 3rd party library you could try Protocol Buffers from google, there is a 'C' and java bindings so integration is pretty straight forward.
Otherwise your best bet is to stick to using DataInputStream and DataOutputStream methods in particalar readUTF() and writeUTF(String). On the Objective-C side a combination of NSData and NSString.
Unless you need the absolute speed and size you could get from doing it your self I would recomend using either protocol buffers or a higher level format like JSON/XML.