sleep tells the thread to wait and do nothing. In a single-thread program like yours, it means your program will do nothing at all. The waiting needs to happen in another thread, or you need to check between received messages if enough time has passed (but then you need to wait for a message for your repeats to fire)