Maintaining accurate data across a network

I’ve decided I might try my hand at some networking with panda3D. Here’s the basic idea behind the project:

The application will be based on a simple concept, that being an individual I’ll call a ‘char’, short for character. There will be multiple chars, and each char will be under the control of a single user. The application will work on the basis of turns, meaning only one user will be doing things at a time, and only when that user performs an action will the data for any chars require updating. All of the users will be able to view the current data for a char at any time.

The data for the chars can be readily represented by simple strings, numbers, and booleans. It will include things like position, stats for dealing, receiving, or avoiding damage, and other basics for a game.

Ideally, I would like to be able to create a class for chars that has all of the data a char might need in it, and when that data is altered, all of the users immediately receive the changes.

I’d bet dollars to donuts that Panda3D can do this with distributed objects, but given my education as an artist rather than a programmer, the vast majority of the networking implementations and examples I’ve found go way over my head.

To dumb things down, what I need is a way I can create a class that looks like this:

class Character:
  def __init__(self):
    self.statistic1 = 10
    self.statistic2 = 20
    self.statistic3 = 100
    self.boolean1 = True
    self.boolean2 = False
    self.boolean3 = True

And allow multiple users on multiple computers to access and alter the data in various instances of that class, and have the alterations they make show up on all of the connected computers.

I honestly don’t know how difficult it would be to do something like that. Could anyone provide a code example on how that would work?

I think you could ‘pickle’ the object … ickle.html

Then send the pickled object over the network.

I’d start by trying to get a client and server just sending strings back and forth to prove the networking concept first. I would google ‘python networking examples’ to learn a bit first before trying to get the panda networking classes working. I haven’t used them but they seem reasonably complex for someone with no experience.

I wonder if there is a more panda specific way to achieve this?

I see what you’re saying, but I think pickling the object and sending the whole thing, as they’re going to have dozens of variables, including dictionaries with dozens of values themselves, would be kind of ugly.

Not an ideal solution, but it might work. Any other ideas?

Generally what I do in my networking is check which variables on the class have changed and then pack that info into the bits of an int, so if var 1 changed, I set the first bit true, if var 2 did not change I set the second bit false, and so on. This goes before the actual data in the Datagram. When the other side receives these bits it will know what getInt, getString, etc. calls to make on the Datagram next.

Well imho I think that your idea with the distributed objects is the way to go. To be honest I never used them but maybe you can find someone in the irc who can help you with them. Or did you already searched for an example in the forum?

I’ve already searched for an example on the forums, and most of what I found was more advanced than what I think I need. Admittedly, I didn’t fully understand most of it.

Look up Pyro. (Not Python Robotics…)

It uses Pickle and lets you make function calls over the network.