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

  • Home
  • SEARCH
  • 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 6585805
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:42:37+00:00 2026-05-25T16:42:37+00:00

I have an HTTP connection with the server side using System.IO.Stream.Read to read the

  • 0

I have an HTTP connection with the server side using System.IO.Stream.Read to read the HTTP request body message.
The problem is that once in a couple of minutes the server gets stuck on the Read statement and doesn’t continue until the socket timeout has been reached or the client has closed the connection.

int bytesRead = 0;

while (bytesRead < contentLength)
{
  int got = stream.Stream.Read(buffer.Buffer, bytesRead, contentLength - bytesRead);
  bytesRead += got;
}
  1. It could happen if the stream did not have the amount of data specified by contentLength variable.
    This is not the case because when following the tcp stream with WireShark I see that the whole message body (as specified by contentLength) has reached the server machine.

  2. It happens only in the first time that the while loop has been “used”, i.e. only in the first time that the stream didn’t have “contentLength” number of bytes to read in one try and the while loop had to be re-entered.

Why does it get stuck and does not continue reading data?

  • 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-25T16:42:37+00:00Added an answer on May 25, 2026 at 4:42 pm

    It seems like it had something to do with the fact that I was using the Read method of both the NetworkStream (that’s the call seen in the code above) and the StreamReader that was created by passing the NetworkStream object to it’s constructor.

    The NetworkStream.Read was used to read the http request message body while the StreamReader.Read was used to read the rest of the request (startline, headers…).
    Although the calls happened synchroniously by the same thread, it may have been the cause to the behavior I experienced.

    When changing the code to work only with a Socket and perform the reading directly from the socket, it has fixed the problem.

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

Sidebar

Related Questions

I have an HTTP server that returns large bodies in response to POST requests
I have a server-side php-script that fetches results from a MySQL table. I am
I have a thread which handles all the HTTP Connections to the server and
i have an Java J2ME application that does (at user request) create HttpConnections to
We have HTTP webservices that are RPC. They return XML representing the object the
I have an HTTP server which is in our internal network and accessible only
I have seen: http://www... ftp://blah.blah... file://blah.blah... unreal://blah.blah... mailto://blah.blah... What is that first section where
I have Django project on Dreamhost server which has several views that returns Json
Hi I have a simple browser that sends a request to yahoo.com which the
From what I understand, each HTTP request uses its own TCP connection (please correct

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.