• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

File copying over socket connection problem

 
Greenhorn
Posts: 2
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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:
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic