Reputation: 16288
I'm new to socket programming, and I've been following several tutorials like this one http://www.myandroidsolutions.com/2012/07/20/android-tcp-connection-tutorial/ and was able to build a client-server architecture over TCP using socket.
The thing is, the tutorials are basic so they teaches you how to send using PrintWriter
and BufferedReader
which seems to write and read String
. I have to encrypt my data and send it as byte[]
, so the question will be:
PrintWriter
and BufferedReader
? if not thenDataOutputStream
and DataInputStream
and several others, but have not found their difference or why use one or another.PS: The encryption part is already done, so don't worry about it as it is not the question :)
Upvotes: 1
Views: 473
Reputation: 1503679
You should use an OutputStream
to write and an InputStream
to read. Those are for binary data - anything with a suffix of Writer
or Reader
is for text data.
You may find DataOutputStream
and DataInputStream
useful - they basically add some services wrapped around a vanilla OutputStream
. But if all you need to do is write a byte[]
to a stream, then plain OutputStream
is fine.
Upvotes: 7