Tunnel(SafeTunnelHandle handle, DeviceConnection owner)
        {
            Log.Write("Tunnel.Tunnel()");

            this.handle = handle;
            this.owner  = owner;
        }
        internal static Tunnel Create(DeviceConnection owner, int localPort, string device, string remoteHost, int remotePort)
        {
            if (device == null)
            {
                throw new ArgumentNullException("device");
            }

            if (remoteHost == null)
            {
                throw new ArgumentNullException("remoteHost");
            }

            IntPtr nativeHandle;

            PlatformAdapter.Instance.nabtoTunnelOpenTcp(out nativeHandle, owner.Owner.GetNativeHandle(), localPort, device, remoteHost, remotePort);

            var safeHandle = new SafeTunnelHandle(nativeHandle);

            var instance = new Tunnel(safeHandle, owner);

            owner.Register(instance);

            return(instance);
        }