Freeze trying basic networking

My attempt as a trivial client:

import direct.directbase.DirectStart
from direct.showbase import DirectObject
from direct.showbase.DirectObject import DirectObject
from direct.task.Task import Task
from pandac.PandaModules import *
import sys


def tskReaderPolling(taskdata):
  print "task Started"
  if cReader.dataAvailable():
    print "task data"
  print "task done"
  return Task.cont

cManager = QueuedConnectionManager()
cListener = QueuedConnectionListener(cManager, 0)
cReader = QueuedConnectionReader(cManager, 0)
cWriter = ConnectionWriter(cManager,0)
port_address=4519  # same for client and server

 # a valid server URL. You can also use a DNS name
 # if the server has one, such as "localhost" or "panda3d.org"
ip_address="fg.98115.net"

 # how long until we give up trying to reach the server?
timeout_in_miliseconds=3000  # 3 seconds

myConnection=cManager.openTCPClientConnection(ip_address,port_address,timeout_in_miliseconds)
if myConnection:
  cReader.addConnection(myConnection)  # receive messages from server
  print "Connected"
  taskMgr.add(tskReaderPolling,"Poll the connection reader",-40)


run()

I have a server, and connecting to it should get some data (used for login). I’m working on my new Panda3D client, however Panda freezes after running my task a few times(variable, 2 to maybe 10). “task data” is never printed and it freezes after “task Started” so I think it is freezing on cReader.dataAvailable(). My server logs indicate that connections were made.

I would like to get data and have panda not freeze, but right now I can’t do either.

I suspect the issue is just that my server is not using Panda’s protocol, and I can’t get raw TCP data with those classes, however, Panda shouldn’t freeze right? I have to force it to quit. Freezing on unexpected network data is very bad.

I could, and may, port some of the networking portions of my server to panda, but I like to keep my options open, so if the panda networking has some protocol (other than basic TCP), I would like to know both what it is (so I can implement it in other languages), and how to get around it (do I simply use other python networking setups?)

Yeah, Panda by default layers its own protocol on datagrams, which just consists of a length and hash code preceding each datagram. If you then send it data that lacks this header, it will read a nonsense length and will block while it tries to read the 27 gazillion bytes it thinks it’s waiting for.

If you’re generating your packets from something else, then you just need to set “raw mode” on your channel, which tells Panda not to expect that header. Use:

cReader.setRawMode(True)

David

Thanks David. That did what I wanted.

Also, once again I’m impressed by panda and python. Printing a datagram works very well!