Dodge ram 4x4 problems

1999 2500 ram quadcab cummins 4wd automatic is having trouble with the 4x4 it started clunking when in 4x4 climbing/pulling up hill the 4x4 indicator light would go off and you would feel the slip and clunk. Then it would ?reingage? and seem to be fine. It got progressively worse rather quickly and just quit going into 4x4 at all. We got the sensor changed as that was bad and then it would go into 4x4 again like normal but upon commencing to climb/pull up hill it started clunking again. I have not used the 4x4 and need it. Do you have any idea what the problem could be? The same thing seems to be happening again. The clunk, the slip feeling, the light indicating 4x4 goes off and then comes back on and the truck seems to be working fine - until it slips/clunks again! Please help, the mechanic has looked at the transfre case and thinks there is no problem there (I am sure that he did not completely disassemble it however). There is no pattern to the problem except that it happens climbing. It might pull fine for a quarter mile then clunk several times in a row. Thanks.

Start with just replacing the u-joints. You do have them, and they are meant to fail first. Unfortunately, it is not easy to replace them anymore.

Check the u-joints in your front axle shafts also. This truck has them, and they do wear out from time to time and will cause symptoms like this.