Steven Akerfeldt
Steven Akerfeldt

Reputation: 629

how can I send an object over tcp socket to an android device?

I have a program written in java which acts as a type of server. I need to send an object over this in a Tcp socket to the phone.

Before now I have just been communicsting string data via PrintWriter and DataInputStream. I was going to try ObjectInputStream but I heard this might fail cross platform due to different java versions etc. My object is serilizable.

Upvotes: 1

Views: 936

Answers (1)

Vaughan Hilts
Vaughan Hilts

Reputation: 2879

You could use a JSON serializer such as this one here to convert the object into a very readable string in whwich you could just use your normal PrintWriter system in place. You would just write the string out to the stream and then restore it on the other end. Simple.

Upvotes: 3

Related Questions