def send_keepalive_msg(socket, msg, peer): while running: socket.sendto(str.encode(msg), peer) time.sleep(timeout)