Removed busy waiting, program works good, except for server closing while receiving messages