writing data form server socket to client socket

G

greatestmclarenfan

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.
 
E

ebby83

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);
}
 
S

Steve Horsley

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);
}

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.
 

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,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top