P
Parker Thompson
Hello,
I am trying to send files over the network using tcp sockets and am
getting horrible speeds even over fast connections, perhaps 10k/sec where
I would expect at least a factor of 10 greater. I feel like this should
be pretty simple, but can't seem to figure it out.
My code is as follows:
//***Receiver code***
InputStream netIn = connectionSocket.getInputStream();
BufferedInputStream bIn = new BufferedInputStream(netIn);
FileOutputStream fileOut = new FileOutputStream(outputFile);
BufferedOutputStream bufOut = new BufferedOutputStream(fileOut);
int b;
while((b = bIn.read()) >= 0){
bufOut.write(b);
receivedBytes++;
if(abort){
cleanup_upon_failure();
}
}
bufOut.flush();
bufOut.close();
netIn.close();
fileOut.close();
//***Sender code***
OutputStream out = connection.getOutputStream();
BufferedOutputStream bOut = new BufferedOutputStream(out);
FileInputStream fIn = new FileInputStream(fileToSend);
BufferedInputStream bIn = new BufferedInputStream(fIn);
while( bIn.available() > 0 ){
bOut.write(bIn.read());
}
bOut.flush();
out.close();
Any suggestions are apreciated. Thanks,
pt.
I am trying to send files over the network using tcp sockets and am
getting horrible speeds even over fast connections, perhaps 10k/sec where
I would expect at least a factor of 10 greater. I feel like this should
be pretty simple, but can't seem to figure it out.
My code is as follows:
//***Receiver code***
InputStream netIn = connectionSocket.getInputStream();
BufferedInputStream bIn = new BufferedInputStream(netIn);
FileOutputStream fileOut = new FileOutputStream(outputFile);
BufferedOutputStream bufOut = new BufferedOutputStream(fileOut);
int b;
while((b = bIn.read()) >= 0){
bufOut.write(b);
receivedBytes++;
if(abort){
cleanup_upon_failure();
}
}
bufOut.flush();
bufOut.close();
netIn.close();
fileOut.close();
//***Sender code***
OutputStream out = connection.getOutputStream();
BufferedOutputStream bOut = new BufferedOutputStream(out);
FileInputStream fIn = new FileInputStream(fileToSend);
BufferedInputStream bIn = new BufferedInputStream(fIn);
while( bIn.available() > 0 ){
bOut.write(bIn.read());
}
bOut.flush();
out.close();
Any suggestions are apreciated. Thanks,
pt.