Server thread writing even after reading end of file. Reading the file again.
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   r_s
Posted On:   Monday, May 2, 2005 11:43 AM

Hi Folks, here is my server code. Seems the client is sending it correctly. A 1045 characters were sent with 1024 bytes and then 21 bytes in the next block. When it is read by the server, I see 1024 and 1024. Here is the code snippet. public void run() { try { int i = 0; byte[] buffer = new byte[1024]; System.out.println("Binded"); int bytesRead=0; while (true) { i++; InputStream fis = socket.getInputStream(); DataInputStream bis = new DataInputStream(fis); FileOutputStream fos = new FileOutputStream(new File("temp" + i + ".dat")); while ((bytesRead=bis.read(buffer)) != -1) { System.o   More>>

Hi Folks, here is my server code. Seems the client is sending it correctly. A 1045 characters were sent with 1024 bytes and then 21 bytes in the next block.

When it is read by the server, I see 1024 and 1024. Here is the code snippet.





			
public void run() {
try {
int i = 0;
byte[] buffer = new byte[1024];
System.out.println("Binded");
int bytesRead=0;
while (true) {
i++;
InputStream fis = socket.getInputStream();
DataInputStream bis = new DataInputStream(fis);
FileOutputStream fos = new FileOutputStream(new File("temp" + i +
".dat"));
while ((bytesRead=bis.read(buffer)) != -1) {
System.out.println("**********" + bytesRead + "**********" + "
");
fos.write(buffer);
fos.flush();

}
if (i == 20) { // It was making a lot of tempxxx.dat files so I am ensuring that it
// writes only 20 files at the max. I want this check removed, since the program
// should have created only file.
fos.close();
bis.close();
fis.close();

}
}




Another issues is, that instead of 1045 bytes which my original file has, this one creates 2048 bytes file with name "temp1.dat" and then creates a lot of "0" bytes file

   <<Less

Re: Server thread writing even after reading end of file. Reading the file again.

Posted By:   Christopher_Koenigsberg  
Posted On:   Monday, May 2, 2005 12:36 PM

sounds like padding out to the buffer boundary.
About | Sitemap | Contact