def send_keepalive_msg(socket, msg, peer): while running: socket.sendto(bytes(msg, 'UTF-8'), peer) time.sleep(timeout)