title: Get data from tcp listener callback in the main thread
body: <p>I've created a transparent proxy for fixing the incoming data, but I want to have all the data from the listening callback in the main thread (where I've opened the socket). What's the best way to do it in the C#? </p>
  
  <p>I am using the library <a href="http://trotinet.sourceforge.net/" rel="nofollow">TrotiNet</a> plus some rewriting logic - fixing the response header. The simple code - as follows</p>
  
  <pre><code>using System;
  using TrotiNet;
  
  namespace TrotiNet.Example
  {
      public class TransparentProxy : ProxyLogic
      {
          public TransparentProxy(HttpSocket clientSocket)
          : base(clientSocket) { }
  
          static new public TransparentProxy CreateProxy(HttpSocket clientSocket)
          {
              return new TransparentProxy(clientSocket);
          }
  
          protected override void OnReceiveRequest()
          {
              Console.WriteLine("-&gt; " + RequestLine + " from HTTP referer " +
                  RequestHeaders.Referer);
          }
  
          protected override void OnReceiveResponse()
          {
              Console.WriteLine("&lt;- " + ResponseStatusLine +
              " with HTTP Content-Length: " +
              (ResponseHeaders.ContentLength ?? 0));
          }
      }
  
      public static class Example
      {
          public static void Main()
          {
              int port = 12345;
              bool bUseIPv6 = false;
  
              var Server = new TcpServer(port, bUseIPv6);
              Server.Start(TransparentProxy.CreateProxy);
  
              Server.InitListenFinished.WaitOne();
              if (Server.InitListenException != null)
                  throw Server.InitListenException;
  
              while (true)
              {
                  //need to get the response data here
                  System.Threading.Thread.Sleep(1000);
              }
  
              //Server.Stop();
          }
      }
  }
  </code></pre>
  
  <p>So mainly, I need to get all the data that comes to OnReceiveResponse in the main thread (Example.Main executor). I do such a proxy for one call - so data not more than 1kB.</p>