Sending files over sockets!
While sending files over sockets,it is ok for small files like text and java.When some larger files like .pdf,.wmv..mp3 etc are sent then the file received is corrupted on the receiving end and the file size is also greater than the sent one.Also the receiving end is waiting infinitely to write.
Actually what might have been happening?Can anyone give me some idea?
The receiving end has the receiving code as shown below:
InputStream in = clientSocket.getInputStream();
byte buf = new byte[Integer.parseInt(headers)];//allocate the size as //the number of bytes available on the stream
//to get the filename and file extensions
String fileExtension=headers.split("\\.");//split on basis of dot to get the
//the last content of the filedetails array will be the extension
//delete already existing file with same name
File file=new File(f2);
System.out.println("Writing as a file\t"+f2);
FileOutputStream fos = new FileOutputStream(new File(f2));
System.out.println("Input streams available are\t"+in.read(buf));
fos.close();//close the fileoutputStream finally