Creating a Server Loop

As I said in my previous thread. I am learning networking. Now I got my clients to connect to my server, it is the time to make server do some actual work. I tried a while(true) loop. It works but take >50% CPU even if it is doing nothing! So it would be wasting resources and that’s not good if I want to host it somewhere. I tried to sleep the thread and it works! But when there will be a huge load on server and it needs each and every millisecond, Sleep would cause the server to lag even more. I could calculate how much milliseconds to make the thread sleep but that will not be accurate because whatever I do, the thread will not resume on the time I want it to. So what’s the way to go? Is sleeping thread the right thing or I need to do something else?

Anyone?