0

Entries on this site reference things being written to "the stream". (I was reading this one about MVC in particular - ASP.NET MVC - Why don't HtmlHelpers render directly to the stream?)

It talks about returning an MvcHtmlString instance vs. writing to the stream. I am having trouble understanding what "the stream" is. And what writing to it would "look like" vs returning MvcHtmlString.

I imagine "the stream" is not just an ASP.NET MVC term? If anybody has a visual representation of this, I think that would help most of all! (if not that's OK too)

Thanks so much!

Community
  • 1
  • 1
A Bogus
  • 3,852
  • 11
  • 39
  • 58

1 Answers1

1

"The Stream" is shorthand for "The HTTP Response Stream", the place where the response bytes are written to send them to the user.

To communicate between any two systems information is sent between them. The information itself is just a series of bytes written to a socket at the sender-side and read from a corresponding socket at the receiver-side. This is the fundamental abstraction of all client-server communication over TCP.

In HTTP, there is a request stream, containing the bytes of the request, written by the client and read by the server, and there is a response stream, containing the bytes of the response, written by the server and read by the client.

Paul Turner
  • 38,949
  • 15
  • 102
  • 166
  • Thanks Tragedian for the reponse. Can you tell why the person who answered the original question I linked to seems to state "returning MvcHtmlString is not part of writing directly to stream"? – A Bogus Nov 09 '12 at 15:31
  • I believe they're referring to the fact that the helper method doesn't invoke `Response.Write` (as they expected) and instead just creates a string which is written by some other component. The helper method could do the write, but it would limit its uses. – Paul Turner Nov 09 '12 at 15:45
  • Thanks Tragedian! You wouldn't happen to know what the "some other component" you mentioned could possibly be? – A Bogus Nov 09 '12 at 19:10
  • Usually, it's the Razor processing engine, reading an element like `@Html.Label(...)`, where the `Label` helper method generated the HTML markup which is then written to the stream. – Paul Turner Nov 12 '12 at 09:18
  • The real thanks is to mark this as your accepted answer for the question (the little gray "tick" under the answer's score). – Paul Turner Nov 12 '12 at 15:58