put udp loop in a function