Can someone explain me networking?

hehe… that was a good one :slight_smile:

Guess why the topic in the manual section is still empty :smiley:
Its either no time or a topic most of the ppl here are not too comfortable with :wink:

(But its a topic I am also highly interested in tbh…)

Regards, Bigfoot29

I read in a previous post that the Panda engine only has client sided network code build it. The original server code is being used by Disney for Toontown, so I can Imagine why they left it out…

Anyway, either write a server to complement the client part, or create your own client / server setup. The last option is what I’m going to do anyway… easier then finding out how Disney did it ^^

There is a networking sample that you can look at to get a better sense of how networking works, but I will try to explain the basics as far as panda is concerned. Also look in direct/src/distributed for most of the modules that networking uses.

There is a ClientRepository and a ServerRepository. The ServerRepository needs a host and a ports for a connection. Make sure that your firewalls arent blocking the ports you are using. Once the ServerRepository is made, you can connect to it with a client repository. The client repository “holds” all of the connected clients so that machine can reference the others through that. Usually, you have to wait for the connection to happen before you can start instancing any DistributedObjects. Once the connection is made, the client repository has create authority meaning you can now start creating DistributedObjects. You do this by calling myConnectionRpository.createWithRequired(“ClassName”, 1). A DistributedObject is the basic object that is instanced over the network. When it is created, it is created on all of the machines connected to the network. When you make a DistributedObject, you need to have the same class defined in the distributed class (dc) file named something like “myFile.dc”. Your config.prc needs to point to this file so panda knows which classes and functions wll be distributed. The dc file tells what arguments are passed when a DistributedObject calls a function that should be performed across the network. Mostly, you use integers and strings as arguments, but there are ways of passing other types (it is a bit harder though). The dc file has its own sort of syntax so look at the sample.dc for reference. Note that all of the names need to match when you are creating these DistributedObjects. To call a function that will be passed over the network you need to call DistributedObject.sendUpdate(“functionName”, [args])

One thing you should know about pandas networking is that it is very client based, meaning the server trusts the clients to report the correct information.

hmm, I can try writing one in python, can I use a network engine/mudule? Can you reccomend me one?

If you’re just starting out, use the asyncore (asynchronous socket handler) alternatively, you could do multithreading, but thats more complicated when just starting out.

Here is some sample code on how to use the asyncore :

import asyncore,socket,struct

IP = '' #your IP (localhost in this case) 
PORT = 3724 #port your server listens on

class MyServerHandler(asyncore.dispatcher):
    def __init__(self,socket,addr):
        # initiate the dispatcher
        # create a send buffer

    def handle_read(self):
        data=self.recv(1024) #receive this amount of data (bytes)
        # As example, I've made this server an Echo server; it sends the   
        # data you've received right back to the client
        # usually, you'd want to id the data for its meaning (ie,  
        # player_moves_left) and send a reply to match it. (ie, ok go     

        if data > 0:
            self.buffer = data     

    def handle_write(self):
        # if there's data in the buffer, send it.
        if len(self.buffer)>0:
    def handle_close(self):

class MyServer(asyncore.dispatcher):
    def __init__(self,port):

        #create a standard TCP socket
        self.bind((IP,PORT)) #bind IP and PORT you're using
        self.listen(5) # accept 5 simultanious connections
    def handle_accept(self): 
        #accept connections and get client address
        if sock_addr:
        # pass new connections to the MySeverHandler class

    def handle_error(self):

def start():
    server= MyServer(PORT) #initiate asyncore server

This is just a quick sample, when you’re building your own server, you’d want to use your own protocol. An easy way to do this would be to send strings: “0621left”
this one starts with the length of the rest of the package
then the id code to know which packet we’re talking about here,
then the data.
for me this packet would mean:
length: 6
opcode: 21 #(ie move)
data: left

I’m not very good at explaining things, if its unclear, dont hesitate to ask.


Yeah I am starting out, I would like some documentation about this, is there?

  • Yellow shrugs

google? :wink:

hmmm… just bumping and thinking about a small client that could do write a line and display the retrieved text… is quite some double posting, but due to the fact that both topics cover the needed information…

Regards, Bigfoot29

Check out this
short text about HTTP
Article on Python Dev Center long but good
Or just look in the Python Documentation there are some articles about Networking


Thank you!
Those will come in handy :slight_smile:

I posted a network sample in this thread:

Think that might be what you need.

so what should I do? Should I use the networkengine of Panda3D, or am I better off with another one?
I have very litle expierience with network programming, so I prefer a simple solution.

Using the panda3d network engine has three large advantages:

  • The C++ code panda uses is faster then pure python script.
  • Its easier to fit into your other panda code (Panda3d doesnt seem to like your own main loops or threads)
  • A lot of work has already been done for you, no need to reinvent the wheel…

So… I’d recommend using the panda netcode.

Besides that, I’d advise to readup on networking in general, cause you really need to know what you’re doing when adding network stuff.

Any recommendations for information about general networking?

I think this may helps.
Or just use Google.


Here are some topics I’d recommend you look into:

  • Sockets (client / server)
  • Variable Types (unsigned char, short, unsigned long etc. In panda they’re called Uint8, Int16, Uint32)
  • Look at some example protocols, I mean, how to process the data thats send between the server and client.
  • UTP and UDP network protocol (dont mistake this with the above)

Happy googling :slight_smile:

And so by the panda3d network engine you mean the ServerRepository and ClientRepository classes?

Which ever part of it you like…

Here is an example:

I cannot find said “sample.dc” file. Can someone please point me to it, or if it no longer exists, provide some simple example of a .dc file? Extremely appreciated!