title: Networkstream or Serializing sending images?
body: <p>New to this, i have been using serializing for sending image data constantly.
  Meaning i save an image in a memorystream, and send it with serializing.</p>
  
  <p>But i don´t understand if i am supposed to use Serializing or Networkstream.
  The only thing i am doing is sending images in a loop.</p>
  
  <p>I have been trying to get a Networkstream to work, but it doesn´t go my way, so here is my code. It sens only 1 image for some reason, when i use serializing it goes constantly.</p>
  
  <pre><code>    private void Initialize()
      {
          NetSerializer.Serializer.Initialize(new Type[] { typeof(MemoryStream) });
          tcplisten = new System.Net.Sockets.TcpListener(IPAddress.Any, 1700);
          tcplisten.Start();
  
      }
      private void Listen()
      {
          try
          {
              using (TcpClient tt1 = tcplisten.AcceptTcpClient())
              {
                  tt1.NoDelay = true;
                  while (checkBox1.Checked)
                  {
                      panel1.BackgroundImage = Image.FromStream(tt1.GetStream());
                  }
              }
          }
          catch
          {
          }
  
      }
  </code></pre>
  
  <p>And here is the send:</p>
  
  <pre><code>    private void Send()
      {
          try
          {                
              string process = Proccessname.Text;               
              using (TcpClient tcp = new TcpClient())
              {
  
                  tcp.NoDelay = true;
                  while (capcon == true)
                  {
  
                      if (tcp.Connected)
                      {
                          PrintWindow(process, tcp.GetStream());
  
                      }
                      else
                      {
                          tcp.Connect(adress);
                      }
                  }
              }
          }
          catch
          {
          }  
      }
  </code></pre>
  
  <p>what  PrintWindow(process, tcp.GetStream()); does is simply, screenshot an a window (process = the name of the process), then where to save it (tcp.GetStream()) which makes it send and stream it (at least i think so).</p>
  
  <p>It does work a bit, if i disconnect and connect etc, it will send an image, but it´s pretty random i think, not sure why i have to do that, i want it to keep sending as long as the loop is active.</p>
  
  <p>(This works perfectly with Serialization and MemoryStream (save the bitmap in a memorystream and use it in Serialization) ).</p>
  
  <p>So this is like 2 questions, depending on the answer of the first.</p>
  
  <p>What is faster for my purpose, (Sending an image), Serialization or NetworkStream?
  If NetworkStream is faster, how can i get it to work, what´s wrong with my code above.</p>
  
  <p>Thanks</p>
  
  <pre><code>          if (tcp.Connected)
                  {
                      MemoryStream ms = new MemoryStream();
  
                      PrintWindow(process, ms);
                      panel1.BackgroundImage = Image.FromStream(ms);
  
                  }
  </code></pre>
  
  <p>This works, so it is getting connected, and the data is getting saved (changed to MemoryStream instead of NetworkStream for this).</p>