Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9206171
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T00:07:10+00:00 2026-06-18T00:07:10+00:00

I have made server client application where server will send a file to client

  • 0

I have made server client application where server will send a file to client and client will receive it and save it in C:/ on any place.
I first send a string “File” in order to tell client to receive file and than server send file name and size to client and then start sending it.
Problem is that client doesnt receive file although it read in loop and get all bytes but doesnt write to required file object. Please have a look on client code I HAVE SHOWN WHERE IT STUCKS

Following is server code :

public void run(){
    try{
        System.out.println("Starting writing file");
        objOut.writeObject("File");
        objOut.flush();

        File f= new File(filePath);
        String name= f.getName();
        int length =(int) f.length();
        objOut.writeObject(name);
        objOut.flush();

        objOut.writeObject(length);
        objOut.flush();

        byte[] filebytes = new byte[(int)f.length()];
        FileInputStream fin= new FileInputStream(f);
        BufferedInputStream bin = new BufferedInputStream(fin);

        bin.read(filebytes, 0, filebytes.length);
        BufferedOutputStream bout = new BufferedOutputStream(objOut);
        bout = new BufferedOutputStream(objOut);
        bout.write(filebytes, 0, filebytes.length);
        bout.flush();      
        System.out.println("File completelty sent");

    }
    catch(Exception ex)
    {
        System.out.println("error on writing file : "+ex.getMessage());
    }

}

Following is client code :

 while(true){
            fobjIn = new ObjectInputStream(fileSock.getInputStream());
            String str = (String) fobjIn.readObject();
            if(str.equals("File"))
            {
                System.out.println("Starting receiving file");
                ReceiveFile();
            }
            System.out.println(str);
        }

 public void ReceiveFile() throws Exception{

     String name =(String)fobjIn.readObject();
   File f = new File("C:/Temp/" +name);
   f.createNewFile();
   int length = (int) fobjIn.readObject();
   FileOutputStream fout = new FileOutputStream(f);
   BufferedOutputStream buffout = new BufferedOutputStream(fout);
   byte[] filebyte = new byte[length];
   int bytesRead=0,current=0;
   bytesRead = fobjIn.read(filebyte, 0, filebyte.length);
    do {
        bytesRead = fobjIn.read(filebyte, current, (filebyte.length-current));
        if(bytesRead > 0) {
            current += bytesRead;
            System.out.println("writting" + bytesRead);
        }
        else break;
     } while(bytesRead > -1);

^^^^^^^IT DOESNT COMEOUT FROM LOOP while begugging^^^^^^^^

    buffout.write(filebyte, 0 , current);
    buffout.flush();
    System.out.println("written");

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T00:07:11+00:00Added an answer on June 18, 2026 at 12:07 am

    You should probably close your stream on the server side when you are done sending, so that the client can be notified that the server is done sending. Or else it’ll just sit there waiting for more data.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have made a client application for LDAP Server(especially for Microsoft AD) in java
I have a client / server application made with C#. Its working fine when
I have a File Transfer Application that sends files and folders. (Server - client)
I have made a full application in JQM using cakePHP as the server side
I have started to write a Python 3.x client application. The server application exists
For learning purposes I am writing a socket based client/server application. I have designed
I have made an application for my client by keeping target iOS as 4.
I have a client and a server application which communicate over .NET 2.0 Remoting
i have made a server using php. The server is getting new information after
i have made columns in some of the tables encrypted in sql server 2008.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.