using
System;
using
System.Net.Sockets;
using
System.Threading;
namespace
PortTransponder
{
class
Program
{
static
void
Main(
string
[] args)
{
TcpListener tl =
new
TcpListener(80);
tl.Start();
while
(
true
)
{
try
{
TcpClient tc1 = tl.AcceptTcpClient();
TcpClient tc2 =
new
TcpClient(
"localhost"
, 3389);
tc1.SendTimeout = 300000;
tc1.ReceiveTimeout = 300000;
tc2.SendTimeout = 300000;
tc2.ReceiveTimeout = 300000;
object
obj1 = (
object
)(
new
TcpClient[] { tc1, tc2 });
object
obj2 = (
object
)(
new
TcpClient[] { tc2, tc1 });
ThreadPool.QueueUserWorkItem(
new
WaitCallback(transfer), obj1);
ThreadPool.QueueUserWorkItem(
new
WaitCallback(transfer), obj2);
}
catch
{ }
}
}
public
static
void
transfer(
object
obj)
{
TcpClient tc1 = ((TcpClient[])obj)[0];
TcpClient tc2 = ((TcpClient[])obj)[1];
NetworkStream ns1 = tc1.GetStream();
NetworkStream ns2 = tc2.GetStream();
while
(
true
)
{
try
{
byte
[] bt =
new
byte
[10240];
int
count = ns1.Read(bt, 0, bt.Length);
ns2.Write(bt, 0, count);
}
catch
{
ns1.Dispose();
ns2.Dispose();
tc1.Close();
tc2.Close();
break
;
}
}
}
}
}