Beispiel #1
0
    public static void Main(String[] args)
    {
        if (args.Length != 2) {
          Console.WriteLine(@"usage: ensimea ADAPTEE_PORT ADAPTED_PORT");
          return;
        }

        var adapteePort = int.Parse(args[0]);
        var adaptedPort = int.Parse(args[1]);

        var serverSocket = new TcpListener(IPAddress.Parse("127.0.0.1"), adaptedPort);
        serverSocket.Start();
        Console.WriteLine("Adapter listening on {0}...", adaptedPort);

        while (true) {
          TcpClient adapterSocket = serverSocket.AcceptTcpClient();
          Socket adapteeSocket = null;

          new Thread(() => {
        try {
          var adapteeEndpoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), adapteePort);
          adapteeSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
          adapteeSocket.Connect(adapteeEndpoint);

          if (adapteeSocket.Connected) {
            var adapter = new SwankAdapter(adapterSocket.GetStream());
            var adaptee = new SwankAdaptee(new NetworkStream(adapteeSocket));
            adapter.Connect(adaptee);
            adaptee.Connect(adapter);
            adapter.KickOff();
            adaptee.KickOff();
            while (adapter.active && adaptee.active) {
              Thread.Sleep(1000);
            }
          }
        } finally {
          adapterSocket.Close();
          adapteeSocket.Close();
        }

          }).Start();
        }
    }
Beispiel #2
0
 public void Connect(SwankAdapter adapter)
 {
     this.adapter = adapter;
 }