Looking for a little help on networking. I see in the manual it says to ask here, so here I am. I already tried a search and basically just came up with a bunch of broken links - lots of references to “Network Example” (along with Rubiks example, and one other - all references made from one page), but when I try to go there, I get a 404.
I don’t think what I’m trying to do should be all that difficult. Just want a socket to listen for messages while still having an interactive window. Messages will be to change colors of objects - if I can get a string in, I think I can figure out what to do with it from there…
Just wondering if anyone had some different input on this… I’ve been going through the Panda API and cross-referencing the DocumentedServer.py - looks neat, but I’m not sure it’s quite what I was hoping for. From what I can tell, this is depending on Python at both ends (packaging up a datagram object, sending it over, then unpackaging it). I was hoping for something that could just use a Socket so I can use a different language to communicate with it. I guess I’m looking for a way to open a socket and create a task that will check for data.
Yes, I think that would work. I’m just having a hard time figuring out how to have a TCP socket listen and handle events while still allowing Panda to do it’s thing. I’m looking into the Twisted framework, but so far it seems that both Twisted and Panda have some sort of internal event loop that pretty much blocks anything else from happening.
Sorry - I’m kind of new to Python… this is definitely a learning experience for me, so if you can give me any pointers, I’d appreciate it!
#Let's start with a simple echo server embedded in code
conn, addr = s.accept()
print 'connected by', addr
data = conn.recv(1024)
if not data: break
#Now, if you run this with panda, it will cause panda
#to stop processing. You need to have this running all
#the time, but you also need panda running all the time
#One of the ways to get around this is to use threading
#this basically says "call this function inside of a
#thread, and let it run in parallel with my process"
#finally, here's the host code to test it with.
print 'Recieved', repr(data)
Panda and Twisted both have their own event loops that want to be in control of program flow, and need to be able to run independantly of each other. In the code I’m working on I was able to solve this problem by creating two program threads, one for Panda and one for Twisted, and using two Queue structures to pass messages between the two threads.
In Panda3D I have a task which runs once per frame, which checks the incoming Queue for messages from the server and updates world objects in Panda as needed. Player inputs call event handlers which place messages on the outgoing queue. In Twisted I have a loop which periodically checks the outgoing queue for messages, and sends them to the server as needed. Messages from the server are places on the incoming queue and sent to the Panda task as they happen.
This may not be the most optimal way to do it and still needs a lot of development, but it does solve the problem of running Twisted and Panda simultaneously.