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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:03:22+00:00 2026-05-24T23:03:22+00:00

server public void HandleConnection(Socket socket) { OutputStream out = socket.getOutputStream(); InputStream in = socket.getInputStream();

  • 0

server

 public void HandleConnection(Socket socket) {
    OutputStream out = socket.getOutputStream();
    InputStream in = socket.getInputStream();
              BufferedReader br = new BufferedReader(new InputStreamReader(in));
              String strLine;
              try {
                while ((strLine = br.readLine()) != null)   {
                  System.out.println (strLine);
                  }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

client

public void httpPostTest() {
        HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost("http://192.168.0.2:8080/");

        try {
            httppost.setEntity(new StringEntity("test"));
            HttpResponse response = httpclient.execute(httppost);
        } catch (ClientProtocolException e) {
         e.printStackTrace();
        } catch (IOException e) {
         e.printStackTrace();
        }

    }

Any thoughts on this? This is all I get back, just the header:

POST / HTTP/1.1
Content-Length: 4
Content-Type: text/plain; charset=ISO-8859-1
Host: 192.168.0.2:8080
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.2 (java 1.5)




public String readLine(InputStream inputStream) {
        StringWriter writer = new StringWriter();
        try {
            IOUtils.copy(inputStream, writer, "ASCII");
        } catch (IOException e) {
            e.printStackTrace();
        }
        String theString = writer.toString();
        return theString.trim();
    }
  • 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-24T23:03:24+00:00Added an answer on May 24, 2026 at 11:03 pm

    From what I understand after doing some reading, BufferedReader is a bad way to read inputStreams from http post. What I was experiencing was that the client making the post would hang and so what the connection handler thread on every post, when I would kill the client the server would stop hanging and I would see the message body. From what I gathered on the internet, the best way to read the input stream is to step through it byte by byte, and exit the loop after the sum of the bytes == the content-length value.

    That said, I’m planning on using Apache HTTPCore instead to handle this as that seems like a better solution

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

Sidebar

Related Questions

I have a server that listens for a connection on a socket: public class
snippet from The Server code : public void run() { try { // Create
SERVER A: public string connStr = Data Source=PH-09-5336;Initial Catalog=InventoryDB;Integrated Security=True; SERVER B: public string
I have an action on my server side: public void Action(Container container) { }
Pyzor uses UDP/IP as the communication protocol. We recently switched the public server to
Is there an equivalent in dbg/cocoa/apple word for the Microsoft public symbol server and
I have Apache running on a public-facing Debian server, and am a bit worried
I have written a custom server control which (pseudo-code) looks like public class MyCustomCtrl
I'm trying to send RSA public key from C# server to iPhone, so I
we have a local staging server running sql server 2000 and a remote public

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.