I'm working on a http proxy application, everything is working fine (client can connect to server and get contents), the problem is neither of HTTP Server or browser close the TCP connection.. I'm not sure if I'm doing it right, here is the code:
while (tcp_link.Connected && _tcp.Connected && !ioError)
{
try
{
Thread.Sleep(100);
if (streamLink.DataAvailable)
{
byte[] l_buffer = new byte[10000];
int l_read = streamLink.Read(l_buffer, 0, l_buffer.Length);
byte[] l_data = new byte[l_read];
Array.Copy(l_buffer, l_data, l_data.Length);
_stream.Write(l_data, 0, l_data.Length);
}
if (_stream.DataAvailable)
{
byte[] c_buffer = new byte[10500];
int c_read = _stream.Read(c_buffer, 0, c_buffer.Length);
byte[] c_data = new byte[c_read];
Array.Copy(c_buffer, c_data, c_data.Length);
streamLink.Write(c_data, 0, c_data.Length);
}
}
catch
{
ioError = true;
}
}
I have same code both sides (proxy client, and proxy server)
NOTE: browser will connect to proxy client (which is on the same computer), and proxy client will connect to proxy server, and obviously proxy server will connect to http server, the reason is i wan't to encode data before sending it out