void server_Connected(object sender, SslServer.ConnectedEventArgs args)
        {
            string connectionInfo = args.RemoteEndPoint.ToString();

            try
            {
                using (TcpClient client = OnConnectTarget(args))
                    using (BinaryLogging logging = new BinaryLogging(_logDirectory, args.RemoteEndPoint, args.LocalEndPoint))
                    {
                        client.Connect();
                        connectionInfo = String.Format("{0} => {1}", args.RemoteEndPoint, client.Client.RemoteEndPoint);
                        string revConnectionInfo = String.Format("{1} => {0}", args.RemoteEndPoint, client.Client.RemoteEndPoint);

                        OnConnectionEstablished(args, client);

                        StreamRedirect recv = new StreamRedirect(args.Stream, client.Stream, connectionInfo, logging.FromServer);
                        StreamRedirect send = new StreamRedirect(client.Stream, args.Stream, revConnectionInfo, logging.FromClient);

                        Log.Verbose("Streaming from {0}", connectionInfo);
                        WaitHandle.WaitAny(new WaitHandle[] { send.WaitClosed, recv.WaitClosed }, -1, true);
                    }
            }
            catch (ThreadAbortException) { throw; }
            catch (Exception e)
            {
                Log.Error(e);
            }
            finally
            {
                args.Close();
                Log.Verbose("Streaming shutdown from {0}", connectionInfo);
            }
        }
Exemplo n.º 2
0
		void server_Connected(object sender, SslServer.ConnectedEventArgs args)
		{
			string connectionInfo = args.RemoteEndPoint.ToString();

			try
			{
				using (TcpClient client = OnConnectTarget(args))
                using (BinaryLogging logging = new BinaryLogging(_logDirectory, args.RemoteEndPoint, args.LocalEndPoint))
				{
					client.Connect();
					connectionInfo = String.Format("{0} => {1}", args.RemoteEndPoint, client.Client.RemoteEndPoint);
					string revConnectionInfo = String.Format("{1} => {0}", args.RemoteEndPoint, client.Client.RemoteEndPoint);

					OnConnectionEstablished(args, client);

                    StreamRedirect recv = new StreamRedirect(args.Stream, client.Stream, connectionInfo, logging.FromServer);
                    StreamRedirect send = new StreamRedirect(client.Stream, args.Stream, revConnectionInfo, logging.FromClient);

					Log.Verbose("Streaming from {0}", connectionInfo);
                    WaitHandle.WaitAny(new WaitHandle[] { send.WaitClosed, recv.WaitClosed }, -1, true);
				}
			}
			catch (ThreadAbortException) { throw; }
			catch (Exception e)
			{
				Log.Error(e);
			}
			finally
			{
				args.Close();
				Log.Verbose("Streaming shutdown from {0}", connectionInfo);
			}
		}