ok well to start of, to stop a while loop, at some point you have to say that statement is false or true (depending what u use in first place). so i.e if you say while(true)
. this will always be true as there is nothing to compare to therefore it will create infinite loop going on forever. however if you say we do something like that
`while(x=true)'
{
x=false;
}
this will ensure that you stop the while loop and you will not enter it again. How? well we enter the while loop under conditon that x is true. as soon as we enter that loop we declare x to be false. therefore on next iteration x will be false and as a result we will not enter while loop. Kinda straight forward isn't it ?
As of the problem it self, i suggest reading THIS article. It is very clear and nicely laid out and it will show you how to write good socket based program:)