using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Net.Sockets; using System.Threading; namespace UDPoverTCP_TunelClient { class UDPoverTCP_TunelClient { static void Greetings(){ Console.WriteLine("Brought to you by The Computer Engineering Group,"); Console.WriteLine("Department of Electronics, UTFSM"); Console.WriteLine("It was just born on October 4th 2010."); Console.WriteLine("Please treat it with care and be patience."); Console.WriteLine("We appreciate your comments to improve it."); } static void Main(string[] args) { Int32 remoteTCPport, localUDPport; string remoteHost = "localhost"; try{ switch (args.Length) { case 2: localUDPport = Convert.ToInt32(args[0]); remoteTCPport = Convert.ToInt32(args[1]); break; case 3: localUDPport = Convert.ToInt32(args[0]); remoteHost = args[1]; remoteTCPport = Convert.ToInt32(args[2]); break; default: Console.WriteLine("Usage: Executable Local_UDP_Port [Remote_Server_Host] Remote_Server_Port"); Console.WriteLine("\"localhost\" is used when Remote_Server_Host is missing."); return; } Greetings(); UdpClient udpServer_sock = new UdpClient(localUDPport); TcpClient tcpClient_sock = new TcpClient(remoteHost, remoteTCPport); GatewayUDP_TCP gateway = new GatewayUDP_TCP(tcpClient_sock, udpServer_sock); Thread fromUDP2TCP_thread = new Thread(gateway.relayDatagramFromUDPtoTCP); fromUDP2TCP_thread.Start(); Thread fromTCP2UDP_thread = new Thread(gateway.relayDatagramFromTCPtoUDP); fromTCP2UDP_thread.Start(); fromUDP2TCP_thread.Join(); fromTCP2UDP_thread.Join(); udpServer_sock.Close(); tcpClient_sock.Close(); } catch (Exception e ) { Console.WriteLine(e.ToString()); } } } }