TCP Proxy server in C#












0














For reverse-engineering purposes I needed to make a TCP proxy server but with GUI for servers and clients management. My solution works quite fine, at least the UI is not getting blocked.



The general idea is that Game can connect to one of the IP's and to one of the ports the IP has. Thus, I need to run a server per each IP:port combination, but it comes down to a server per each possible port since all IP's are redirected to one PC.



Here is the top-form-class that starts all servers:



public class GameServer
{
public string Hostname;
public IPAddress IP;
public List<int> Ports = new List<int>();
}

public partial class ServersForm : Form
{
public List<GameServer> Servers { get; private set; } = new List<GameServer>(); // Populated externally
private List<IntermediateServer> _proxyServers;
private Dictionary<string, ClientForm> _clients = new Dictionary<string, ClientForm>();

public ServersForm()
{
InitializeComponent();
StartAll(null, null);
}

// Will later be triggered from UI, hence the prototype
public void StartAll(object sender, EventArgs args)
{
_proxyServers = new List<IntermediateServer>();

foreach (var server in _resources.Servers)
{
foreach (var port in server.Ports)
{
_proxyServers.Add(new IntermediateServer(server.IP, port, OnClientConnected));
}
}
}

private void OnClientConnected(TcpClient client, IPAddress serverIP, int serverPort)
{
var ep = (IPEndPoint)client.Client.RemoteEndPoint;
var clientIP = ep.Address.ToString();
var clientPort = ep.Port;
var clientForm = new ClientForm(client.GetStream(), clientPort, serverIP, serverPort);
_clients.Add(clientIP, clientForm);
Application.Run(clientForm);
}

private void OnFormClosing(object sender, FormClosingEventArgs e)
{
foreach (var client in _clients)
{
client.Value.Stop();
}

foreach (var proxy in _proxyServers)
{
proxy.Stop();
}
}
}


IntermediateServer acts as a server for the actual Game that listens on given port number and calls the OnClientConnected callback:



public class IntermediateServer
{
private IPAddress _serverIP;
private int _serverPort;
private TcpListener _listener; // Server for the actual game
private Thread _thread;
private bool _isRunning = false;
private Action<TcpClient, IPAddress, int> _clientCallback;

public IntermediateServer(IPAddress ip, int port, Action<TcpClient, IPAddress, int> clientCallback)
{
_serverIP = ip;
_serverPort = port;
_clientCallback = clientCallback;

_isRunning = true;

_listener = new TcpListener(IPAddress.Any, _serverPort);
_listener.Start();

_thread = new Thread(Listen);
_thread.Start();
}

public void Listen()
{
while (_isRunning)
{
try
{
var client = _listener.AcceptTcpClient();
_clientCallback(client, _serverIP, _serverPort);
}
catch (Exception e)
{
#if DEBUG
Console.WriteLine(e);
#endif
}
}
}

public void Stop()
{
_isRunning = false;
_listener.Stop();
}
}


OnClientConnected callback creates new GUI form for each client. This form is responsible for initiating proxy connection and will further be used to display packets information:



public partial class ClientForm : Form
{
private NetworkStream _clientStream;
private NetworkStream _serverStream;

private Proxy _clientProxy;
private Proxy _serverProxy;

private TcpClient _client; // Client for the actual server

public ClientForm(NetworkStream clientStream, int clientPort, IPAddress serverIP, int serverPort)
{
_client = new TcpClient();
_client.Connect(serverIP, serverPort);

_clientStream = clientStream;
_serverStream = _client.GetStream();

_clientProxy = new Proxy(_serverStream, _clientStream);
_serverProxy = new Proxy(_clientStream, _serverStream);

InitializeComponent();
Start();
}

public void Start()
{
_clientProxy.Start();
_serverProxy.Start();
}

public void Stop()
{
// Yet unresolved issue
Invoke((MethodInvoker)delegate
{
Close();
});
}

private void OnFormClosing(object sender, FormClosingEventArgs e)
{
_serverProxy.Stop();
_clientProxy.Stop();
}
}


And finally Proxy class. The idea of this class is to have two instances per client, each provided with client stream (the one from Intermediate class) and server stream (the one from ClientForm class) with the difference that one instance can read client and write to server and the other one does the opposite. This way I can inject data without issues:



public class Proxy
{
private NetworkStream _read;
private NetworkStream _write;

private Thread _queueThread;
private Thread _listenThread;

private ConcurrentQueue<byte> _queue = new ConcurrentQueue<byte>();

private bool _isRunning = false;

public Proxy(NetworkStream read, NetworkStream write)
{
_read = read;
_write = write;
}

public void Start()
{
_isRunning = true;

_queueThread = new Thread(ProcessQueue);
_queueThread.Start();

_listenThread = new Thread(Listen);
_listenThread.Start();
}

private void Listen()
{
int length = 0;
var data = new byte[4096];
while (_isRunning)
{
Array.Clear(data, 0, data.Length);
try
{
if (!_read.DataAvailable)
{
Thread.Sleep(1);
}
else if ((length = _read.Read(data, 0, data.Length)) > 0)
{
var message = data.Take(length).ToArray();
_queue.Enqueue(message);
}
}
catch (IOException e)
{
// Client disconnected
_isRunning = false;
}
catch (Exception e)
{
_isRunning = false;
}
}
}

private void ProcessQueue()
{
while (_isRunning)
{
try
{
if (!_queue.IsEmpty)
{
for (var i = 0; i < _queue.Count; i++)
{
byte message;
while (!_queue.TryDequeue(out message)) ;
_write.Write(message, 0, message.Length);
}
}
}
catch (Exception e)
{
_isRunning = false;
}
}
}

public void Stop()
{
_isRunning = false;
}
}


While I tried my best, I am afraid this code is not much thread-safe. What can be improved here?










share|improve this question



























    0














    For reverse-engineering purposes I needed to make a TCP proxy server but with GUI for servers and clients management. My solution works quite fine, at least the UI is not getting blocked.



    The general idea is that Game can connect to one of the IP's and to one of the ports the IP has. Thus, I need to run a server per each IP:port combination, but it comes down to a server per each possible port since all IP's are redirected to one PC.



    Here is the top-form-class that starts all servers:



    public class GameServer
    {
    public string Hostname;
    public IPAddress IP;
    public List<int> Ports = new List<int>();
    }

    public partial class ServersForm : Form
    {
    public List<GameServer> Servers { get; private set; } = new List<GameServer>(); // Populated externally
    private List<IntermediateServer> _proxyServers;
    private Dictionary<string, ClientForm> _clients = new Dictionary<string, ClientForm>();

    public ServersForm()
    {
    InitializeComponent();
    StartAll(null, null);
    }

    // Will later be triggered from UI, hence the prototype
    public void StartAll(object sender, EventArgs args)
    {
    _proxyServers = new List<IntermediateServer>();

    foreach (var server in _resources.Servers)
    {
    foreach (var port in server.Ports)
    {
    _proxyServers.Add(new IntermediateServer(server.IP, port, OnClientConnected));
    }
    }
    }

    private void OnClientConnected(TcpClient client, IPAddress serverIP, int serverPort)
    {
    var ep = (IPEndPoint)client.Client.RemoteEndPoint;
    var clientIP = ep.Address.ToString();
    var clientPort = ep.Port;
    var clientForm = new ClientForm(client.GetStream(), clientPort, serverIP, serverPort);
    _clients.Add(clientIP, clientForm);
    Application.Run(clientForm);
    }

    private void OnFormClosing(object sender, FormClosingEventArgs e)
    {
    foreach (var client in _clients)
    {
    client.Value.Stop();
    }

    foreach (var proxy in _proxyServers)
    {
    proxy.Stop();
    }
    }
    }


    IntermediateServer acts as a server for the actual Game that listens on given port number and calls the OnClientConnected callback:



    public class IntermediateServer
    {
    private IPAddress _serverIP;
    private int _serverPort;
    private TcpListener _listener; // Server for the actual game
    private Thread _thread;
    private bool _isRunning = false;
    private Action<TcpClient, IPAddress, int> _clientCallback;

    public IntermediateServer(IPAddress ip, int port, Action<TcpClient, IPAddress, int> clientCallback)
    {
    _serverIP = ip;
    _serverPort = port;
    _clientCallback = clientCallback;

    _isRunning = true;

    _listener = new TcpListener(IPAddress.Any, _serverPort);
    _listener.Start();

    _thread = new Thread(Listen);
    _thread.Start();
    }

    public void Listen()
    {
    while (_isRunning)
    {
    try
    {
    var client = _listener.AcceptTcpClient();
    _clientCallback(client, _serverIP, _serverPort);
    }
    catch (Exception e)
    {
    #if DEBUG
    Console.WriteLine(e);
    #endif
    }
    }
    }

    public void Stop()
    {
    _isRunning = false;
    _listener.Stop();
    }
    }


    OnClientConnected callback creates new GUI form for each client. This form is responsible for initiating proxy connection and will further be used to display packets information:



    public partial class ClientForm : Form
    {
    private NetworkStream _clientStream;
    private NetworkStream _serverStream;

    private Proxy _clientProxy;
    private Proxy _serverProxy;

    private TcpClient _client; // Client for the actual server

    public ClientForm(NetworkStream clientStream, int clientPort, IPAddress serverIP, int serverPort)
    {
    _client = new TcpClient();
    _client.Connect(serverIP, serverPort);

    _clientStream = clientStream;
    _serverStream = _client.GetStream();

    _clientProxy = new Proxy(_serverStream, _clientStream);
    _serverProxy = new Proxy(_clientStream, _serverStream);

    InitializeComponent();
    Start();
    }

    public void Start()
    {
    _clientProxy.Start();
    _serverProxy.Start();
    }

    public void Stop()
    {
    // Yet unresolved issue
    Invoke((MethodInvoker)delegate
    {
    Close();
    });
    }

    private void OnFormClosing(object sender, FormClosingEventArgs e)
    {
    _serverProxy.Stop();
    _clientProxy.Stop();
    }
    }


    And finally Proxy class. The idea of this class is to have two instances per client, each provided with client stream (the one from Intermediate class) and server stream (the one from ClientForm class) with the difference that one instance can read client and write to server and the other one does the opposite. This way I can inject data without issues:



    public class Proxy
    {
    private NetworkStream _read;
    private NetworkStream _write;

    private Thread _queueThread;
    private Thread _listenThread;

    private ConcurrentQueue<byte> _queue = new ConcurrentQueue<byte>();

    private bool _isRunning = false;

    public Proxy(NetworkStream read, NetworkStream write)
    {
    _read = read;
    _write = write;
    }

    public void Start()
    {
    _isRunning = true;

    _queueThread = new Thread(ProcessQueue);
    _queueThread.Start();

    _listenThread = new Thread(Listen);
    _listenThread.Start();
    }

    private void Listen()
    {
    int length = 0;
    var data = new byte[4096];
    while (_isRunning)
    {
    Array.Clear(data, 0, data.Length);
    try
    {
    if (!_read.DataAvailable)
    {
    Thread.Sleep(1);
    }
    else if ((length = _read.Read(data, 0, data.Length)) > 0)
    {
    var message = data.Take(length).ToArray();
    _queue.Enqueue(message);
    }
    }
    catch (IOException e)
    {
    // Client disconnected
    _isRunning = false;
    }
    catch (Exception e)
    {
    _isRunning = false;
    }
    }
    }

    private void ProcessQueue()
    {
    while (_isRunning)
    {
    try
    {
    if (!_queue.IsEmpty)
    {
    for (var i = 0; i < _queue.Count; i++)
    {
    byte message;
    while (!_queue.TryDequeue(out message)) ;
    _write.Write(message, 0, message.Length);
    }
    }
    }
    catch (Exception e)
    {
    _isRunning = false;
    }
    }
    }

    public void Stop()
    {
    _isRunning = false;
    }
    }


    While I tried my best, I am afraid this code is not much thread-safe. What can be improved here?










    share|improve this question

























      0












      0








      0







      For reverse-engineering purposes I needed to make a TCP proxy server but with GUI for servers and clients management. My solution works quite fine, at least the UI is not getting blocked.



      The general idea is that Game can connect to one of the IP's and to one of the ports the IP has. Thus, I need to run a server per each IP:port combination, but it comes down to a server per each possible port since all IP's are redirected to one PC.



      Here is the top-form-class that starts all servers:



      public class GameServer
      {
      public string Hostname;
      public IPAddress IP;
      public List<int> Ports = new List<int>();
      }

      public partial class ServersForm : Form
      {
      public List<GameServer> Servers { get; private set; } = new List<GameServer>(); // Populated externally
      private List<IntermediateServer> _proxyServers;
      private Dictionary<string, ClientForm> _clients = new Dictionary<string, ClientForm>();

      public ServersForm()
      {
      InitializeComponent();
      StartAll(null, null);
      }

      // Will later be triggered from UI, hence the prototype
      public void StartAll(object sender, EventArgs args)
      {
      _proxyServers = new List<IntermediateServer>();

      foreach (var server in _resources.Servers)
      {
      foreach (var port in server.Ports)
      {
      _proxyServers.Add(new IntermediateServer(server.IP, port, OnClientConnected));
      }
      }
      }

      private void OnClientConnected(TcpClient client, IPAddress serverIP, int serverPort)
      {
      var ep = (IPEndPoint)client.Client.RemoteEndPoint;
      var clientIP = ep.Address.ToString();
      var clientPort = ep.Port;
      var clientForm = new ClientForm(client.GetStream(), clientPort, serverIP, serverPort);
      _clients.Add(clientIP, clientForm);
      Application.Run(clientForm);
      }

      private void OnFormClosing(object sender, FormClosingEventArgs e)
      {
      foreach (var client in _clients)
      {
      client.Value.Stop();
      }

      foreach (var proxy in _proxyServers)
      {
      proxy.Stop();
      }
      }
      }


      IntermediateServer acts as a server for the actual Game that listens on given port number and calls the OnClientConnected callback:



      public class IntermediateServer
      {
      private IPAddress _serverIP;
      private int _serverPort;
      private TcpListener _listener; // Server for the actual game
      private Thread _thread;
      private bool _isRunning = false;
      private Action<TcpClient, IPAddress, int> _clientCallback;

      public IntermediateServer(IPAddress ip, int port, Action<TcpClient, IPAddress, int> clientCallback)
      {
      _serverIP = ip;
      _serverPort = port;
      _clientCallback = clientCallback;

      _isRunning = true;

      _listener = new TcpListener(IPAddress.Any, _serverPort);
      _listener.Start();

      _thread = new Thread(Listen);
      _thread.Start();
      }

      public void Listen()
      {
      while (_isRunning)
      {
      try
      {
      var client = _listener.AcceptTcpClient();
      _clientCallback(client, _serverIP, _serverPort);
      }
      catch (Exception e)
      {
      #if DEBUG
      Console.WriteLine(e);
      #endif
      }
      }
      }

      public void Stop()
      {
      _isRunning = false;
      _listener.Stop();
      }
      }


      OnClientConnected callback creates new GUI form for each client. This form is responsible for initiating proxy connection and will further be used to display packets information:



      public partial class ClientForm : Form
      {
      private NetworkStream _clientStream;
      private NetworkStream _serverStream;

      private Proxy _clientProxy;
      private Proxy _serverProxy;

      private TcpClient _client; // Client for the actual server

      public ClientForm(NetworkStream clientStream, int clientPort, IPAddress serverIP, int serverPort)
      {
      _client = new TcpClient();
      _client.Connect(serverIP, serverPort);

      _clientStream = clientStream;
      _serverStream = _client.GetStream();

      _clientProxy = new Proxy(_serverStream, _clientStream);
      _serverProxy = new Proxy(_clientStream, _serverStream);

      InitializeComponent();
      Start();
      }

      public void Start()
      {
      _clientProxy.Start();
      _serverProxy.Start();
      }

      public void Stop()
      {
      // Yet unresolved issue
      Invoke((MethodInvoker)delegate
      {
      Close();
      });
      }

      private void OnFormClosing(object sender, FormClosingEventArgs e)
      {
      _serverProxy.Stop();
      _clientProxy.Stop();
      }
      }


      And finally Proxy class. The idea of this class is to have two instances per client, each provided with client stream (the one from Intermediate class) and server stream (the one from ClientForm class) with the difference that one instance can read client and write to server and the other one does the opposite. This way I can inject data without issues:



      public class Proxy
      {
      private NetworkStream _read;
      private NetworkStream _write;

      private Thread _queueThread;
      private Thread _listenThread;

      private ConcurrentQueue<byte> _queue = new ConcurrentQueue<byte>();

      private bool _isRunning = false;

      public Proxy(NetworkStream read, NetworkStream write)
      {
      _read = read;
      _write = write;
      }

      public void Start()
      {
      _isRunning = true;

      _queueThread = new Thread(ProcessQueue);
      _queueThread.Start();

      _listenThread = new Thread(Listen);
      _listenThread.Start();
      }

      private void Listen()
      {
      int length = 0;
      var data = new byte[4096];
      while (_isRunning)
      {
      Array.Clear(data, 0, data.Length);
      try
      {
      if (!_read.DataAvailable)
      {
      Thread.Sleep(1);
      }
      else if ((length = _read.Read(data, 0, data.Length)) > 0)
      {
      var message = data.Take(length).ToArray();
      _queue.Enqueue(message);
      }
      }
      catch (IOException e)
      {
      // Client disconnected
      _isRunning = false;
      }
      catch (Exception e)
      {
      _isRunning = false;
      }
      }
      }

      private void ProcessQueue()
      {
      while (_isRunning)
      {
      try
      {
      if (!_queue.IsEmpty)
      {
      for (var i = 0; i < _queue.Count; i++)
      {
      byte message;
      while (!_queue.TryDequeue(out message)) ;
      _write.Write(message, 0, message.Length);
      }
      }
      }
      catch (Exception e)
      {
      _isRunning = false;
      }
      }
      }

      public void Stop()
      {
      _isRunning = false;
      }
      }


      While I tried my best, I am afraid this code is not much thread-safe. What can be improved here?










      share|improve this question













      For reverse-engineering purposes I needed to make a TCP proxy server but with GUI for servers and clients management. My solution works quite fine, at least the UI is not getting blocked.



      The general idea is that Game can connect to one of the IP's and to one of the ports the IP has. Thus, I need to run a server per each IP:port combination, but it comes down to a server per each possible port since all IP's are redirected to one PC.



      Here is the top-form-class that starts all servers:



      public class GameServer
      {
      public string Hostname;
      public IPAddress IP;
      public List<int> Ports = new List<int>();
      }

      public partial class ServersForm : Form
      {
      public List<GameServer> Servers { get; private set; } = new List<GameServer>(); // Populated externally
      private List<IntermediateServer> _proxyServers;
      private Dictionary<string, ClientForm> _clients = new Dictionary<string, ClientForm>();

      public ServersForm()
      {
      InitializeComponent();
      StartAll(null, null);
      }

      // Will later be triggered from UI, hence the prototype
      public void StartAll(object sender, EventArgs args)
      {
      _proxyServers = new List<IntermediateServer>();

      foreach (var server in _resources.Servers)
      {
      foreach (var port in server.Ports)
      {
      _proxyServers.Add(new IntermediateServer(server.IP, port, OnClientConnected));
      }
      }
      }

      private void OnClientConnected(TcpClient client, IPAddress serverIP, int serverPort)
      {
      var ep = (IPEndPoint)client.Client.RemoteEndPoint;
      var clientIP = ep.Address.ToString();
      var clientPort = ep.Port;
      var clientForm = new ClientForm(client.GetStream(), clientPort, serverIP, serverPort);
      _clients.Add(clientIP, clientForm);
      Application.Run(clientForm);
      }

      private void OnFormClosing(object sender, FormClosingEventArgs e)
      {
      foreach (var client in _clients)
      {
      client.Value.Stop();
      }

      foreach (var proxy in _proxyServers)
      {
      proxy.Stop();
      }
      }
      }


      IntermediateServer acts as a server for the actual Game that listens on given port number and calls the OnClientConnected callback:



      public class IntermediateServer
      {
      private IPAddress _serverIP;
      private int _serverPort;
      private TcpListener _listener; // Server for the actual game
      private Thread _thread;
      private bool _isRunning = false;
      private Action<TcpClient, IPAddress, int> _clientCallback;

      public IntermediateServer(IPAddress ip, int port, Action<TcpClient, IPAddress, int> clientCallback)
      {
      _serverIP = ip;
      _serverPort = port;
      _clientCallback = clientCallback;

      _isRunning = true;

      _listener = new TcpListener(IPAddress.Any, _serverPort);
      _listener.Start();

      _thread = new Thread(Listen);
      _thread.Start();
      }

      public void Listen()
      {
      while (_isRunning)
      {
      try
      {
      var client = _listener.AcceptTcpClient();
      _clientCallback(client, _serverIP, _serverPort);
      }
      catch (Exception e)
      {
      #if DEBUG
      Console.WriteLine(e);
      #endif
      }
      }
      }

      public void Stop()
      {
      _isRunning = false;
      _listener.Stop();
      }
      }


      OnClientConnected callback creates new GUI form for each client. This form is responsible for initiating proxy connection and will further be used to display packets information:



      public partial class ClientForm : Form
      {
      private NetworkStream _clientStream;
      private NetworkStream _serverStream;

      private Proxy _clientProxy;
      private Proxy _serverProxy;

      private TcpClient _client; // Client for the actual server

      public ClientForm(NetworkStream clientStream, int clientPort, IPAddress serverIP, int serverPort)
      {
      _client = new TcpClient();
      _client.Connect(serverIP, serverPort);

      _clientStream = clientStream;
      _serverStream = _client.GetStream();

      _clientProxy = new Proxy(_serverStream, _clientStream);
      _serverProxy = new Proxy(_clientStream, _serverStream);

      InitializeComponent();
      Start();
      }

      public void Start()
      {
      _clientProxy.Start();
      _serverProxy.Start();
      }

      public void Stop()
      {
      // Yet unresolved issue
      Invoke((MethodInvoker)delegate
      {
      Close();
      });
      }

      private void OnFormClosing(object sender, FormClosingEventArgs e)
      {
      _serverProxy.Stop();
      _clientProxy.Stop();
      }
      }


      And finally Proxy class. The idea of this class is to have two instances per client, each provided with client stream (the one from Intermediate class) and server stream (the one from ClientForm class) with the difference that one instance can read client and write to server and the other one does the opposite. This way I can inject data without issues:



      public class Proxy
      {
      private NetworkStream _read;
      private NetworkStream _write;

      private Thread _queueThread;
      private Thread _listenThread;

      private ConcurrentQueue<byte> _queue = new ConcurrentQueue<byte>();

      private bool _isRunning = false;

      public Proxy(NetworkStream read, NetworkStream write)
      {
      _read = read;
      _write = write;
      }

      public void Start()
      {
      _isRunning = true;

      _queueThread = new Thread(ProcessQueue);
      _queueThread.Start();

      _listenThread = new Thread(Listen);
      _listenThread.Start();
      }

      private void Listen()
      {
      int length = 0;
      var data = new byte[4096];
      while (_isRunning)
      {
      Array.Clear(data, 0, data.Length);
      try
      {
      if (!_read.DataAvailable)
      {
      Thread.Sleep(1);
      }
      else if ((length = _read.Read(data, 0, data.Length)) > 0)
      {
      var message = data.Take(length).ToArray();
      _queue.Enqueue(message);
      }
      }
      catch (IOException e)
      {
      // Client disconnected
      _isRunning = false;
      }
      catch (Exception e)
      {
      _isRunning = false;
      }
      }
      }

      private void ProcessQueue()
      {
      while (_isRunning)
      {
      try
      {
      if (!_queue.IsEmpty)
      {
      for (var i = 0; i < _queue.Count; i++)
      {
      byte message;
      while (!_queue.TryDequeue(out message)) ;
      _write.Write(message, 0, message.Length);
      }
      }
      }
      catch (Exception e)
      {
      _isRunning = false;
      }
      }
      }

      public void Stop()
      {
      _isRunning = false;
      }
      }


      While I tried my best, I am afraid this code is not much thread-safe. What can be improved here?







      c# tcp proxy






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 42 mins ago









      lolbas

      16315




      16315



























          active

          oldest

          votes











          Your Answer





          StackExchange.ifUsing("editor", function () {
          return StackExchange.using("mathjaxEditing", function () {
          StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
          StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
          });
          });
          }, "mathjax-editing");

          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "196"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: false,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f210484%2ftcp-proxy-server-in-c%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown






























          active

          oldest

          votes













          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Code Review Stack Exchange!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          Use MathJax to format equations. MathJax reference.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f210484%2ftcp-proxy-server-in-c%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Morgemoulin

          Scott Moir

          Souastre