import socket import time import threading class Reader(threading.Thread): def __init__(this, udp_sock): threading.Thread.__init__(this) this.udp_sock = udp_sock this.running = 0 def run(this): this.running = 1 while this.running: try: text, addr = this.udp_sock.recvfrom(8000) print text except: pass udp_sock=socket.socket(socket.AF_INET, socket.SOCK_DGRAM) udp_sock.bind(("", 5555)) reader = Reader(udp_sock) reader.start() while not reader.running: time.sleep(1.0) while 1: time.sleep(1.0) print "!!" udp_sock.sendto("hi", ('localhost', 5556)) print " done."