def forward(data, port):
    print("Forwarding: '%s' from port %s" % (data, port))
sock = socket(AF_INET, SOCK_DGRAM)
sock.bind(('localhost', port))
sock.sendto(data, (targetHost, listenPort))

def listen(host, port):
    listenSocket = socket(AF_INET, SOCK_DGRAM)
listenSocket.bind((host, port))
while True:
    pass
Python port forwarding/multiplexing server