title: Http Web Server - big response packet issue C#
body: <p>I have been making a HTTP web server for mainly a application generated uptime monitor but wanted to expand it so its more general use. A problem I am having with it is when a client requests for an image (for example) that is 1MB+ I don't know how to split the image data up to fit inside the MTU size of packets.</p>
  
  <p>Below is the code I am using to send the data. (StreamWriter AutoFlush is enabled)</p>
  
  <pre><code>        private void sendResponse(Stream stream, string fileLocation, bool useGzip, string contentType, string ResponseLine, bool CloseConnection, string server)
      {
          writer.Write(ResponseLine + "/r/n");
          writer.Write("Server: " + server + "/r/n");
          if (CloseConnection == true)
              writer.Write("Connection: close" + "/r/n");
          else
              writer.Write("Connection: keep-alive" + "/r/n");
  
          //if (useGzip == true)
          //    writer.WriteLine("Content-Encoding: gzip")
          writer.Write("Content-Type: " + contentType + "/r/n");
          writer.Write("Content-Length: " + stream.Length + "/r/n");
          writer.Write("Accept-Ranging: bytes" + "/r/n");
          writer.Write("" + "/r/n");
  
          byte[] data = new byte[stream.Length];
          stream.Read(data, 0, data.Length);
          writer.Write(data);
          writer.Flush();
      }
  </code></pre>
  
  <p>Also, in Wireshark the capture shows 500+ packets of max size with continuation or tcp segment, does HTTP have a way of splitting up big responses into multiple packets without tcp segmentation?</p>
  
  <p>Solved - Using sockets instead of the TcpClient class worked a treat and removing the stream overlays (BinaryReader/BinaryWriter)</p>