±???êμày?2ê?á?C#???ú×a·¢ó?·¨?£·??í??′ó?ò1?′ó?ò2????£??ì?·???è???£o
?aà?ò?á′?ó3389μ?ê±oò?aày
ày×ó1£oá??óa?ú?÷μ?3389???úá?2?é?£?òò?a??·?·à?e???ò??í?1?×?á??T??£????ü·??êa?ú?÷μ???±e???ú±èè?80?£
ày×ó2£oá??óa?ú?÷μ???o??ùóD???ú??á?2?é?£¨??·????úí??ò??·à?e??í?1?×?á??T??£?£????ü1433é?襣?μ?ê???·??éò?á??ó??μ??3D????ú?£
?a??·?·¨£o
μúò??????òμ¥£???Dèòa3ìDò?ú??·??a80£???á??ó??80£?3ìDòê?μ?êy?Yoó£?·¢?íμ???±??úμ?3389£?í?ê±′ó??3389ê?μ?êy?Yoó·μ??μ????£3ìDò?íê?ò????D×a???£
using System; using System.Net.Sockets; using System.Threading; namespace PortTransponder { class Program { static void Main(string[] args) { TcpListener tl = new TcpListener(80); //?aà??a??·??éò?±???á??ó2¢?ò?′±???ó?μ????ú tl.Start(); while (true) //?aà?±?D?ó??-?·£??éò??óê?2??1ò????í?§ //òò?a?ò·¢??????·t??óDê±ò??????ú2?DD?í??ò??????ú??á? { //????μ?òa???íê?ò?μ?3ìDòê?μ???·¢?íμ?êy?Y°üoóá¢?ì?a2????3ì×??D×a try { TcpClient tc1 = tl.AcceptTcpClient(); //?aà?ê?μè′yêy?Y?ù?′DD??±?£?2??á100%??ó?cpu TcpClient tc2 = new TcpClient("localhost", 3389); tc1.SendTimeout = 300000; //éè?¨3?ê±£?·??ò???ú??ò??±±???ó?£??′ê1ê§è¥á??ó 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 { //?aà?±?D?try catch£?·??òá??óò?μ??D??3ìDò?í±àà£á? //òaê?μˉ3?′í?óìáê?è??ú?÷?′?????í??á? 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; } } } } }
?£í?±????ùê???′ó?òμ?C#3ìDòéè??óD?ù°??ú?£
除声明外,跑步客文章均为原创,转载请以链接形式标明本文地址
C#???ú×a·¢ó?·¨?ê?a
本文地址: http://www.paobuke.com/develop/c-develop/pbk23101.html
C#???ú×a·¢ó?·¨?ê?a
本文地址: http://www.paobuke.com/develop/c-develop/pbk23101.html