I have a program which acts as both a server and a client.
I have to read data from the the server socket, process the first few
lines, and then write the remaining data to a client socket. This data
may contain images.
Can you tell me the quickest/efficient way of doing this? I would like
to avoid reading/writing data bit by bit.
Thanks,
Swapnil.
use BufferedReader and PrintWriter classes , open 2 connections of each
, one each to the origin and one to the destination ... cross link both
of them and ur done ..
r1 , r2
w1 , w2
String line;
while ( !(line=r1.readLine() ).equals(null) ) {
w2.write(line);
}
// do something
while ( !(line=r2.readLine() ).equals(null) ) {
w1.write(line);
}
Steve Horsley - 16 Feb 2006 20:05 GMT
> use BufferedReader and PrintWriter classes , open 2 connections of each
> , one each to the origin and one to the destination ... cross link both
[quoted text clipped - 13 lines]
> w1.write(line);
> }
No. That will totally corrupt any binary data like image files.
You must use InputStream and OutputStream. These have
read(byte[]) and write(byte[]) methods. Use a byte[] of 1600
bytes and you should get good performance.