panda crashing UDP

hey guys,

can somebody identify why panda is crashing with this (no error msg just remains unresponsive) ?

class World(DirectObject):
  def __init__(self):
    #base.dusableMouse()
    
    panda = loader.loadModel("panda")
    panda.reparentTo(render)
    
    # Server program

 
    # Set the socket parameters
    host = "localhost"
    port = 2000
    buf = 1024
    addr = (host,port)

    # Create socket and bind to address
    UDPSock = socket(AF_INET,SOCK_DGRAM)
    UDPSock.bind(addr)

    # Receive messages
    while 1:
            data,addr = UDPSock.recvfrom(buf)
            if not data:
                    print "Client has exited!"
                    break
            else:
                    print "\nReceived message '", data,"'"
                    panda.setScale(data)
                    

    # Close socket
    UDPSock.close()
    
   
       


w = World()        #Create an instance of our class
run()              #Run the simulation

If I dont declare a class, and just run it without, it runs fine.

Thank you!

you have an infinite loop in your class… while 1. it will run forever, so it will prevent panda itself to run.
you might want to run the receive thing as a panda-task instead.

Thanks ThomasEgi for the reply
I tried this :

class World(DirectObject):
  def __init__(self):
    #base.dusableMouse()
    
    panda = loader.loadModel("panda")
    panda.reparentTo(render)
    
       
    taskMgr.add(self.udpCheck, 'udpCheck')
    
  def udpCheck(self,task):
    # Server program

    
    # Set the socket parameters
    host = "localhost"
    port = 2000
    buf = 1024
    addr = (host,port)
    
    # Create socket and bind to address
    UDPSock = socket(AF_INET,SOCK_DGRAM)
    UDPSock.bind(addr)
    # Receive messages
    while 1:
            data,addr = UDPSock.recvfrom(buf)   
            if not data:
                    print "Client has exited!"
                    break
            else:
                    print "\nReceived message '", data,"'"
                    panda.setScale(data)
                    

    # Close socket
    UDPSock.close()
        
    return Task.cont

           
    


w = World()        #Create an instance of our class
run()              #Run the simulation

and this :



class World(DirectObject):
  def __init__(self):
    #base.dusableMouse()
    
    panda = loader.loadModel("panda")
    panda.reparentTo(render)
    
    # Server program

    
    # Set the socket parameters
    host = "localhost"
    port = 2000
    self.buf = 1024
    addr = (host,port)
    
    # Create socket and bind to address
    self.UDPSock = socket(AF_INET,SOCK_DGRAM)
    self.UDPSock.bind(addr)
    # Receive messages
    if 1:
        taskMgr.add(self.udpCheck, 'udpCheck')
            

    else:
         # Close socket
         UDPSock.close()
    
        
    
  def udpCheck(self,task):
    data,addr = self.UDPSock.recvfrom(self.buf)   
    if not data:
            print "Client has exited!"
    else:
            print "\nReceived message '", data,"'"
            panda.setScale(data)
    
        
    return Task.cont

           
    


w = World()        #Create an instance of our class
run()              

unfortunately no luck, both keep crashing with the same way
Any suggestions on what I am doing wrong?

Thanks.

Actually, it’s not a “crash”. I believe recvfrom waits until it receives something (it just keeps waiting and only returns when it receives something).
You’re better off with threading (you’ll have to wait for 1.6 for that, or compile the CVS), or use a polling-based networking system.
Panda also has builtin UDP classes, I believe.

(This is just a guess what could be wrong. To know for sure whether this is the issue, press control^C at the console (when it froze) and check the traceback. If the traceback begins in the function recvfrom, I’m right.)

pro-rsoft you are actually correct, since once I sent data to it, it unfreezes (producing more errors :slight_smile: )

I don’t think I will manage to compile the CVS, is there anyway I can download it from someone already compiled it?

also where can I find more information on the builtin UDP classes?

Thank you!

Threading won’t help you here (unless you go to full OS-supported true threads). You need to use non-blocking reads instead. Look into putting your socket into non-blocking mode, and then you can read from it without waiting for a response. Or, use the select() function to check if there is a response ready before you call recvfrom().

David

Hi David,

Thanks for the reply. I have put my sockets into non-blocking mode, by using this code :

...
def udpCheck(self,task):
    data,addr = self.UDPSock.recvfrom(self.buf)
    self.UDPSock.setblocking(0)  
    if not data:
            print "Client has exited!"
    else:
            #print "\nReceived message '", data,"'"
            scale = (ord(data)) * 1            
            print scale
            self.panda.setScale(scale)
...

but I get this error :

any ideas why?

That’s the way non-blocking mode works. Instead of blocking, it throws that exception. You’re supposed to use try…except to listen for the exception, and when you catch it, do whatever you ought to do if there is no data to receive yet.

David

why just not use the UDP interface provided with panda3d?

hi treeform, thanx for the reply.

Can you tell me where I can find some details on the UDP interface provided with panda3d?

nvm, stupid question.

manual and forums…

I will try using that and if i have any problems will ask again.

thanks.