sure, here is the complete client code:
import direct.directbase.DirectStart
from direct.distributed.PyDatagram import PyDatagram
from direct.distributed.PyDatagramIterator import PyDatagramIterator
from direct.showbase.DirectObject import DirectObject
from direct.showbase.ShowBase import ShowBase
from direct.task import Task
from pandac.PandaModules import *
from pandac.PandaModules import ConnectionWriter
from pandac.PandaModules import QueuedConnectionListener
from pandac.PandaModules import QueuedConnectionManager
from pandac.PandaModules import QueuedConnectionReader
from direct.gui.DirectGui import *
#from direct.gui.DirectGui import DirectFrame
#from pandac.PandaModules import TextNode
#--Networking Stuff
class Client(DirectObject):
def __init__(self):
print "Initializing client test"
self.port = 9099
self.ip_address = "darkrift.dyndns-server.com"
self.timeout = 3000 # 3 seconds to timeout
self.cManager = QueuedConnectionManager()
self.cListener = QueuedConnectionListener(self.cManager, 0)
self.cReader = QueuedConnectionReader(self.cManager, 0)
self.cWriter = ConnectionWriter(self.cManager, 0)
self.Connection = self.cManager.openTCPClientConnection(self.ip_address, self.port, self.timeout)
if self.Connection:
taskMgr.add(self.tskReaderPolling, "read the connection listener", -40)
# this tells the client to listen for datagrams sent by the server
print "Connected to Server"
self.cReader.addConnection(self.Connection)
print "Message Recieved..."
print "\n"
myPyDatagram = PyDatagram()
myPyDatagram.addUint8(100)
# adds an unsigned integer to your datagram
myPyDatagram.addString("first string of text")
# adds a string to your datagram
myPyDatagram.addString("second string of text")
# adds a second string to your datagram
self.cWriter.send(myPyDatagram, self.Connection)
# fires it off to the server
#self.cManager.closeConnection(self.Connection)
#print "Disconnected from Server"
# uncomment the above 2 lines if you want the client to
# automatically disconnect. Or you can just
# hit CTRL-C twice when it's running to kill it
# in windows, I don't know how to kill it in linux
#taskMgr.add(self.tskReaderPolling, "read the connection listener", -40)
def tskReaderPolling(self, task):
if self.cReader.dataAvailable():
datagram = PyDatagram()
if self.cReader.getData(datagram):
self.processServerMessage(datagram)
return Task.cont
def processServerMessage(self, netDatagram):
myIterator = PyDatagramIterator(netDatagram)
print myIterator.getString()
#taskMgr.add(self.tskReaderPolling, "read the connection listener", -40)
class DarkRift(ShowBase):
def __init__(self):
ShowBase.__init__(self)
#------------load models and stuff here------------------
#--Lighting
alight = AmbientLight("alight")
alight.setColor(VBase4(0.2, 0.2, 0.2, 1))
alnp = render.attachNewNode(alight)
render.setLight(alnp)
#--Directional Light for SUN
dlight = DirectionalLight('dlight')
dlight.setColor(VBase4(0.8, 0.8, 0.5, 1))
dlnp = render.attachNewNode(dlight)
dlnp.setHpr(0, -60, 0)
render.setLight(dlnp)
#--static models (non-animated)
self.environ = self.loader.loadModel("Models/Antris V")
self.environ.setScale(1.25, 1.25, 1.25)
self.environ.setTwoSided(True)
self.environ.reparentTo(self.render)
#tex = loader.loadTexture("Textures/space009.jpg")
#self.setTexture(tex,1)
self.environ.setPos(-0, 60, 0)
#--Background Starfeilds
self.skysphere = loader.loadModel("Models/Antrisystemstars.bam")
self.skysphere.setBin("background", 1)
self.skysphere.setDepthWrite(0)
self.skysphere.reparentTo(render)
taskMgr.add(self.skysphereTask, "SkySphere Task")
#task for rendering the skysphere each frame and moving it relitive to the camera
def skysphereTask(self, task):
self.skysphere.setPos(base.camera, 0, 0, 0)
return task.cont
# Main Loop
Client = Client()
app = DarkRift()
#taskMgr.add(sendOutput, "Send the output to the server", -39)
#taskMgr.add(tskReaderPolling, "Poll the connection reader", -38)
############################################################
# GUI using DirectGUI
############################################################
'''myFrame = DirectFrame(frameColor=(0, 0, 0, 1),frameSize= (-1, 1, -1, 1), pos=(1, -1, -1))
bk_text = "This is a test Does it work?"
textObject = OnscreenText(text = bk_text, pos = (0.95, -0.95),
scale = 0.05, fg = (1,0.5,0.5,1), align=TextNode.ACenter, mayChange=1)
#--Callback to set text
def setText():
bk_text = "Button Clicked"
textObject.setText(bk_text)
#--Add a button
b = DirectButton(text = ("OK","Click me!","Rolling Over","Disabled"), scale = .07, command = setText)'''
app.run()
no idea why its makeing 2 panda windows but for now I have the GUI code block commented till I figure it out.