https://en.bitcoin.it/wiki/Getwork this is what you want, but to be honest don't reinvent the wheel their are a lot of different miners out their and they do it very well, so i would say your wasting your time, unless your some kind of genius who knows how to optimize to get 1 T/Hash on a CPU don't even try.
If everyone were to listen to this we wouldn't get anywhere... One mans wasted time is another mans treasure.