Why don't you take a look at the Box2D Source. In there you'll be able to see how the distance joint works. It might be a bit complex, but the part I would start with is "solveVelocityConstraints" in the b2DistanceJoint.
If all you are looking for is a very simplistic implementation then you could try this;
- Find the distance between ObjectA and ObjectB
- Find the difference the distance and the desired rest distance.
- Apply a force, proportional to this difference value, to each body, in the direction of the other body.
It might look similar to the following for a basic implementation (disclaimer, I don't have the ability to test this right now).
Vec3 dir = ObjectB.position - ObjectA.position;
float mag = (dir.length - targetLength) * 0.5f;
dir.normalise();
ObjectA.velocity += dir * -diff;
ObjectB.velocity += dir * diff;
Keep in mind this is a very simplistic implementation and is potentially unstable. Also keep in mind that this would never let the body "rest", so the two objects would be constantly moving towards and then away from each other, although it might be too small to see. This is why you would be best either using box2D or working out how it works and then replicating it.