change the timeout and run forever loop

use a timeout and loop to allow none blocking sockets to be used