aspose file tools*
The moose likes I/O and Streams and the fly likes File copying over socket connection problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "File copying over socket connection problem" Watch "File copying over socket connection problem" New topic
Author

File copying over socket connection problem

Mathew Fulton
Greenhorn

Joined: Sep 10, 2011
Posts: 2

Hey guys!

I'm busy developing a chat program and want to add a file sending capability.
I managed to write a standalone server and client to JUST send a file and it worked.

However, when I incorporated it into my chat program it does not work properly. The file is copied but it doesn't break out of the while loop.
I'm doing it using a byte[] array and a DataInputStream.

Here is the basics of what it looks like (and it works in the standalones)



Now the client works perfect, sending everything and printing the last number of bytes. But the server does not pick up the last lot and so doesn't break out of the loop.

Thanks
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19784
    
  20

Welcome to the Ranch!

I don't think this will solve the problem, but there is a flaw in your program - the read(byte[]) method does not necessarily fill the entire array. Especially the last read will fill it only partially (unless the total size is a multiple of the array size). Use the following code to fix this:


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: File copying over socket connection problem