I have a small problem, I have 2 tasks, 1 task for input, and one testing task (for receiving data on a socket connection)

I’m in testing mode, so there are print statements in my code, just to see what it gives:

taskMgr.doMethodLater(1, CatchData, "networking")
def CatchData(task):
            buffer = sck.recv(1024)
            if buffer == "test": 
                print buffer
                print task.delayTime
            return task.again

So, the first second (befoce “catchdata” is executed, my user input (for walking around) works.), than it displays:

And after that, my app hangs, can’t do nothing. What I expect is that it would execute CatchData every second.

Thanks for your time.

Your socket must be set to blocking mode, there recv waits indefinitely until it receives data. The easy fix here is to set the socket to nonblocking mode (see “setblocking” in the Python reference), in which case recv will not return anything if there is no data available instead of blocking until there is data available.

(Alternatively, you could add your task to a task chain and have it use a separate thread, but this is probably not necessary.)

Still, it doesn’t look like your code should work as you might receive “te” one frame and “st” the other. You should probably store the data in a variable and keep appending to it until it contains what you need; alternatively you could use the “yield” keyword in the task until it has gathered the entire message.

Yep, that was the problem, it’s solved.