added try-except for socket timeout in while loop.