Update via UDP

Hello,

I’m trying to update a camera position via UDP. I’m pretty new to this, and I know I’m doing something(s) totally wrong.

With the code listed below, nothing happens when I push UDP values… not even the print “got data” or “updated camera” stuff.

I know my UDP sending mechanism is working, because if I rearrange the code, I do get the print “got data” when I push UDP packets, but when I get success here, the model wont render at all! :confused:

I’m sure this would be an easy fix for an experienced user… I’d love your thoughts!

class RenderApp(ShowBase):
    def __init__(self):
        ShowBase.__init__(self)
        
        # set window properties
        wp = WindowProperties()
        wp.setTitle('SCREEN 1')
        base.win.requestProperties(wp)        

        # adjust camera for screen 1
        base.camList[0].setPos(0, -20, 0)
        base.camList[0].lookAt(0, 20, 0)
        
        # load model
        self.environ = self.loader.loadModel("model.egg")
        self.environ.reparentTo(self.render)
        
        # setup networking
        host = "127.0.0.1"
        port = 5432
        self.bufsize = 1024
        self.addr = (host,port)
        self.ssocket = socket(AF_INET, SOCK_DGRAM)
        #self.ssocket.settimeout(.01)
        self.ssocket.bind(self.addr)
            
    def readData(self):
        try:
            data,addr = self.ssocket.recvfrom(self.bufsize)
            print "got data!"
            return data
        except:
            return 0
            
    def updateCameras(self, task):
        data = self.readData()
        if data:
            base.camList[0].setX(data)
            print "updated camera!"
            
app = RenderApp()
run() 

you need to add your task to the taskmanager. otherwise it will never run.

and you need to return a task continue , otherwise, the task will run exactly once and then ends.

Ah, I see… thank you for pointing me in the right direction! Adding the “return task.cont” and adding the task to “taskMgr.add” seemed to get things going.
Thanks again!