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 8768177
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:00:33+00:00 2026-06-13T17:00:33+00:00

my app for college work.. DOC to PDF == my server: one thread per

  • 0

my app for college work..

DOC to PDF

==

my server:

one thread per requisition

        server = new ServerSocket(5000);

        while (true) {
            Socket cliente = server.accept();
            Thread thread = new Thread(new Requisitor(cliente));
            thread.start();
        }

my class Requisitor (run method)

@Override
public void run() {
    // receive doc binary
    receive();
    // doc to pdf
    Conversor converson = new Conversor(new File("docs/"+cliente.getInetAddress().getHostAddress()+".doc"),new File("pdfs/"+cliente.getInetAddress().getHostAddress()+".pdf"));
    converson.converter();
    //response pdf binary to client
    response();
}

but the method receive() is not called.. only when i disconect client socket.

my client socket:

    Client cliente = new Client();
    cliente.connect();
    cliente.send(); // send doc binary

    boolean flag = true;

    while (flag) {
        if(!cliente.streamIsEmpty()){ // wait for conversion
            cliente.receive(); // receive pdf
            flag = false;
        }
    }


    cliente.disconect()

my receive method

        InputStream in = cliente.getInputStream();
        BufferedInputStream stream = new BufferedInputStream(in);
        FileOutputStream out = new FileOutputStream("docs/"+cliente.getInetAddress().getHostAddress()+".doc");

        byte[] buffer = new byte[1024];
        int length = 0;

        while((length = stream.read(buffer, 0, 1024)) != -1) {
            out.write(buffer, 0, length);
        }

        out.flush();
        stream.close();

any idea? 🙁

  • 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-13T17:00:34+00:00Added an answer on June 13, 2026 at 5:00 pm

    Here you read until -1 is returned by the stream read. This happens when the socket is closed. Try closing the OutputStream within cliente.send() (not the whole socket) after it writes the document.

        while((length = stream.read(buffer, 0, 1024)) != -1) {
            out.write(buffer, 0, length);
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to make an android app. It is about counting Bunks for college
I'm relatively new to XCode and I m working on photo collage App ,
I'm relatively new to X Code and I m working on photo collage App
this is my Teackback: D:\zjm_demo\app>appcfg.py upload_data --config_file=upload/str_loader.py --filename=upload/a.csv --kind=College --url=http://localhost:8100/remote_api Uploading data records. app_id
App Engine recently announced support for Cross Group (XG) transactions ; one would expect
I am creating an app that allows college students to download their study material
I am trying to build a small app for a college with WPF, it
I am making an app for my college where we have to parse RSS
I am creating a new rails app as a learning project. I have already
I am a broke college student. I have built a small web app in

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.