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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:29:19+00:00 2026-05-31T13:29:19+00:00

I am doing two succssive calls to my servlet from android in this way:

  • 0

I am doing two succssive calls to my servlet from android in this way:

//FIRST CONNECTION
URL url = new URL("http://172.16.32.160:8080/xyz/check_availability");
            HttpURLConnection connection =(HttpURLConnection) url.openConnection();
            connection.setDoOutput(true);
            ObjectOutputStream out=new ObjectOutputStream(connection.getOutputStream());

            String a="xya";
            String b="xsw";
            out.writeObject(a);

            out.flush();


            ObjectInputStream in=new ObjectInputStream(connection.getInputStream());
            String s=(String)
            in.readObject();
            in.close();
            out.close();

                Toast.makeText(getApplicationContext(), "1", Toast.LENGTH_LONG).show();


            //SECOND CONNECTION 


            URL url1 = new URL("http://172.16.32.160:8080/xyz/check_availability");
            HttpURLConnection connection1 = (HttpURLConnection)url1.openConnection();
            connection1.setDoOutput(true);


            ObjectOutputStream out1=new ObjectOutputStream(connection1.getOutputStream());
            out1.writeObject(b);
            out1.flush();

            ObjectInputStream in1=new ObjectInputStream(connection1.getInputStream());
                String str=(String)
                in1.readObject();
                in1.close();
                out1.close();
                Toast.makeText(getApplicationContext(), "2", Toast.LENGTH_LONG).show();

The above code works well because I’ve closed the outputstream of the first connection after closing the inputstream. But If I close the outputstream after sending the object, the second input stream throws an exception:

java.io.StreamCorruptedException

Why should the outputstream be closed after closing the inputstream?

NOTE
    If someone knows the actual answer or the proper reason as to why it does not work in Android,     please answer. Till then I will accept the answer given by EJP – that it is a bug in android.

  • 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-05-31T13:29:20+00:00Added an answer on May 31, 2026 at 1:29 pm

    Looks like a bug in Android to me.

    In Java whence this comes, closing the ObjectOutputStream at any time over an HttpURLConnection does nothing except flush the output (because the connection has to stay up to receive the response). Closing the input stream of an HttpURLConnection closes the entire connection, so a subsequent close of the ObjectOutputStream would do nothing.

    I suspect Android does something bad to the connection when you do the ObjectOutputStream.close() first, such as closing it.

    I would omit the ObjectOutputStream.close() altogether, you don’t need it in either platform. The flush() is sufficient.

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

Sidebar

Related Questions

I would like to call a servlet from another servlet doing two things: setting
Basically you have two ways for doing this: for (int x = 0; x
Recently I'm doing some work with two Series in pandas: The first Series contains
What is the simplest way of doing two way encryption in common PHP installs?
I'm doing this for two hours and nothing. This is the date in JSON:
hi i am new to iphone. what i am doing is creating two classes
I am doing two queries SELECT * FROM datedim WHERE year = YEAR(now()); and
I haven't really done a two way binding project before, so this might be
I am doing a join on two tables. One is a user's table and
I am doing the exact same thing in two classes, and in one the

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.