read/write data byte-per-byte to and from a socket

C

crash.test.dummy

the usual data handling that i know in sockets is by using an input
stream and output stream for reading and writing data, respectively:

PrintWriter out = new PrintWriter(clientSocket.getOutputStream(),
true);
BufferedReader in = new BufferedReader(new
InputStreamReader(clientSocket.getInputStream()));

1. how do i read data byte-per-byte from a socket?
2. how do i write data byte-per-byte to a socket?

thanks.
 
K

Knute Johnson

crash.test.dummy said:
the usual data handling that i know in sockets is by using an input
stream and output stream for reading and writing data, respectively:

PrintWriter out = new PrintWriter(clientSocket.getOutputStream(),
true);
BufferedReader in = new BufferedReader(new
InputStreamReader(clientSocket.getInputStream()));

1. how do i read data byte-per-byte from a socket?
2. how do i write data byte-per-byte to a socket?

thanks.

Just use the InputStream and OutputStream that you get from the socket.

Actually it is interesting that you asked this question this way. There
are a lot of posts here periodically where people are having trouble
getting their data moved around. It is almost always caused by using
some extension of FilterOutputStream/InputStream and available. Use
InputStream/OutputStream for binary data and buffer it yourself or add a
BufferedInputStream/OutputStream. For text or string data use
BufferedReader/Writer. Those will cover 99% of all the I/O you need to do.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,733
Messages
2,569,439
Members
44,829
Latest member
PIXThurman

Latest Threads

Top