UDP Delay

Hi there,

This post is similar to an existing post from 2005, which was then unresolved.
https://discourse.panda3d.org/viewtopic.php?t=626&highlight=udp

I’m working on an arts project that connects Panda3d with Cycling74’s MaxMSP, and am using the SimpleOSC(Open Sound Control) python module to achieve this. Simple OSC works perfectly in python, sending and receiving messages immediately. But when Panda is running/rendering there is a 1-2 second delay in Panda receiving the UDP messages. (This was the same as the above post).

Is there a work round for this in Panda to get UDP messages working without delay? or can someone suggest another tested method of communicating without delay between MaxMSP and Panda3D?

Thanks in advance.

Greg

We have never experienced this problem in-house. We use Panda’s TCP and UDP communications layer while rendering, and packets are delivered consistently without delay.

Clearly something is wrong in your case (and similarly for the user who posted the linked thread), but I don’t have enough information to help solve it. Certainly there is nothing Panda is doing that is intentionally causing network delays; I can only surmise that there must be some interplay between the graphics subsystem and the operating system network layer.

We have seen cases where Panda can demand so much CPU that it completely starves out all other processes running on your box, including the system threads that process networking messages. (It seems that Windows has an appallingly bad process scheduler.) Try putting something like:

client-sleep 0.01

in your Config.prc, which should degrade your frame rate by a tiny bit but give other processes on the same box a chance to run.

David

Thanks David for the quick reply.

I have had success, and just had to get the simpleOSC commands in the right order within panda.

For those interested, here is the code for setting up a UDP connection with Panda using SimpleOSC, so Panda can then talk to MAXmsp. Need to download and place in the python lib the SimpleOSC python module, and then use in MaxMSP a UDPsend object.

import direct.directbase.DirectStart
from direct.showbase.DirectObject import DirectObject
from direct.task.Task import Task
import osc

#functions to handle OSC messages
def OSCprintStuff(*msg):
    print "printing in the printStuff function ", msg

def myUDPTest():
    osc.getOSC(inSocket) # listen to incomming OSC in this socket

#initialize ocs, including port.
osc.init()
inSocket = osc.createListener("127.0.0.1", 3001)
#test OSC address
osc.bind(OSCprintStuff, "/testaddress")

#then need to set up a task to check for in coming messages.
class World(DirectObject):

    def __init__( self ):

        # task
        taskMgr.add( self.OSCcheck, 'osctask' )

    def OSCcheck( self, task ):

        myUDPTest()
        return Task.cont

w = World()
run()

i just downloaded simpleOSC from here:
ixi-software.net/content/bod … ython.html

and the API are a bit changed.

this is an example with a new API
expected OSC messages fo /mouse/position that contains 2 number: mouse x and mouse y

import sys
 
from direct.showbase.ShowBase import ShowBase
from direct.task import Task
from direct.actor.Actor import Actor

import simpleOSC as osc

class MyApp(ShowBase):
    def __init__(self):
        ShowBase.__init__(self)
 
        # enviroment
        foo_camera = lambda x: self.camera.setPos(0, -20, 3) or Task.cont   # ugly python use 
        self.taskMgr.add(foo_camera, "SpinCameraTask")

        def release():
            osc.closeOSC()
            sys.exit()
        self.accept('escape', release) 

        # osc
        self.initOscServer()
        self.oscPosition = 0,0,0

        # actor 
        self.pandaActor = Actor("models/panda-model") #,
        self.pandaActor.setScale(0.005, 0.005, 0.005)
        self.pandaActor.reparentTo(self.render)
     
    def initOscServer(self):
        #functions to handle OSC messages 
        def handler1(addr, tags, data, source): # *msg): 
            self.oscPosition = data[0]/100.0, data[1]/100.0, 0 
        
        #initialize ocs, including port. 
        osc.initOSCServer("127.0.0.1", 12345) 
        osc.setOSCHandler("/mouse/position", handler1 ) 
        self.osc = osc
        
        taskMgr.add( self.doStuffsWithActor, 'doing' ) 
        

    def doStuffsWithActor(self, task):
        self.pandaActor.setPos(*self.oscPosition)
        return Task.cont
 
app = MyApp()
app.run()
print 'am i here?'

ps i’ve tried also pyOSC i found here: github.com/ptone/pyosc
but there are some delay problem that i do not understand… so i changed the module and everything works fine : )