Base server code attribute error.

Using the code example in the manual on networking and datagrams as a starting point I have an issue when I try and start the server example.

Please keep in mind this is the very base of the server and the code is nearly identical to what is givin in the manual at this point as this is simply a starting point for me.

Here is the server code I am starting with:

# -- Darkrift Server

import direct.directbase.DirectStart
from pandac.PandaModules import *
from direct.distributed.PyDatagram import PyDatagram
from direct.distributed.PyDatagramIterator import PyDatagramIterator
from direct.task import Task
from direct.actor import Actor

#--Instantate connection classes
cManager = QueuedConnectionManager()
cListener = QueuedConnectionListener(cManager, 0) # <--Changed these to cManager from self.cManager
cReader = QueuedConnectionReader(cManager, 0)
cWriter = ConnectionWriter(cManager, 0)

#--keep track of connections in the array by callback later but for now store them in an array
activeConnections=[]

#--tcp/ip connection port
port_address=9099

#--Backlog sets the max connection attempts we ignore
backlog=1000

tcpSocket = cManager.OpenTCPServerRendezvous(port_address, backlog)
cListener.addConnection(tcpSocket)

#--add some polling tasks to do connection polling
taskMgr.add(tskListenerPolling, "Poll the connection listener", -39)
taskMgr.add(tskReaderPolling, "poll the connection reader", -40)

#--Handle incomming connections and hand them off to QueuedConnectionManager
def tskListenerPolling(taskdata):
    if cListener.newConnectionAvailible():
        rendezvous - PointerToConnection()
        netAddress = NetAddress()
        newConnection = PointerToCOnnection()

        if cListener.getNewConnection(rendezvous,netAddress,newConnection):
            newConnection = newConnection.p()
            #--remember new connection
            activeConnections.append(newConnection)
            #--Start reading the connection
            cReader.addConnection(newConnection)
    return Task.cont

#--QueuedConnectionManager starts processing incomming packets here
def tskReaderPolling(taskdata):
    if cReader.dataAvailable():
        datagram=NetDatagram()  # <--Catch incomming data here
        if cReader.getData(datagram):
            darkriftProcessDataFunction(datagram) # <--changed process name my need replaced with myProcessDataFunction(datagram)
    return Task.cont

#--Broadcast a message to all clients connected to the server
darkriftPyDatagram=darkriftNewPyDatagram()
for aClient in activeConnections:
     cWriter.send(darkriftPyDatagram, aClient)
     

# --Terminate connection when we are finished with the client
for aClient in activeConnections:
    cReader.removeConnection(aClient)
    activeConnections=[]

#--Close the listener down
cManager.closeConnection(tcpSocket)

when I try running this i get this error:

C:\Panda3D-1.7.1\DarkRift\src>python darkriftserver.py
DirectStart: Starting the game.
Known pipe types:
  wglGraphicsPipe
(all display modules loaded.)
Traceback (most recent call last):
  File "darkriftserver.py", line 26, in <module>
    tcpSocket = cManager.OpenTCPServerRendezvous(port_address, backlog)
AttributeError: 'libpanda.QueuedConnectionManager' object has no attribute 'Open
TCPServerRendezvous'

any pointers as to how to fix this ?

Python is case-sensitive. The method name is “openTCPServerRendezvous”, not “OpenTCPServerRendezvous”.

David

DOh, nice catch lol

now i dont know if this is indentation related or its not importing the imports but here is the next error:

C:\Panda3D-1.7.1\DarkRift\src>ppython darkriftserver.py
DirectStart: Starting the game.
Known pipe types:
  wglGraphicsPipe
(all display modules loaded.)
Traceback (most recent call last):
  File "darkriftserver.py", line 30, in <module>
    taskMgr.add(tskListenerPolling, "Poll the connection listener", -39)
NameError: name 'tskListenerPolling' is not defined

EDIT:: Disregard this error please, got ahead of myself again with asking for help. moved the taskMgr code to the bottom of the file and it fixed it. so we are all good again for now :blush: