Win a copy of Terraform in Action this week in the Cloud forum!
    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 ...
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • Al Hobbs
  • salvin francis

Sending file over network through sockets using serializable object

Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
I am writing a code to transfer a file from server machine to client machine.
I am using Object protocol for communication. ie client sends a filerequest object , server recognizes it and send the response back in form of object again.
My problem is :

I read the file on server machine , in chunks of 1024 bytes.
I try to write an object to Objectoutputstram of socket.
For doing this, If I store the data read from file in any outputstream/Bufferedoutputstream etc then it throws exception : NOTserializable. Please guide me, what should I use to store the data from file and write it as object.

Here is my code:


ObjectOutputStream objOut = new ObjectOutputStream (socket.getoutputStream());


public Object processfile()

byte[] packet = new byte[1024];
int bytes_trans=0; //transfered bytes
int bytes_read;//read bytes
ByteArrayOutputStream bout = new ByteArrayOutputStream();
ObjectOutputStream out;

try {
FileInputStream fin = new FileInputStream(filename);

while( (bytes_read =, 0,packet.length)) >= 0)

bytes_trans = bytes_trans + bytes_read;
System.out.println("Total bytes transferred :"+ bytes_trans);
System.out.println("Done! ");
//out = new ObjectOutputStream(bout);


//return out;

Posts: 1638
IntelliJ IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
Kindly do not Cross post the same question multiple times.
This is the duplicate
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic