UDP exact_type [SOLVED]

Hello,

I am trying on client side, to etablish UDP connection to my Server on port 9097

class networkUdp(DirectObject,threading.Thread):
	reference=None
	def __init__(self,nom=''):
		threading.Thread.__init__(self)
		self.nom = nom
		self.Terminated = False
		self.stopThread=False
		self.updateChar={}
		self.lastRun=globalClock.getRealTime()
		networkUdp.reference=self

		port_address=9098  # same for client and server
		self.cManager = QueuedConnectionManager()
		self.cReader = QueuedConnectionReader(self.cManager, 0)
		self.cWriter = ConnectionWriter(self.cManager,0)
		ip_address="127.0.0.1"

		self.myConnection=self.cManager.openUDPConnection(port_address)
		if self.myConnection:
			self.cReader.addConnection(self.myConnection)  # receive messages from server
			self.serverAddr = NetAddress() 
			self.serverAddr.setHost(ip_address, 9097) 
			
		
		self.listOfMessage=[] 
		
	def run(self):
		i = 0
		while not self.stopThread:
			while self.cReader.dataAvailable()!=False:
				datagram=NetDatagram()  # catch the incoming data in this instance
				if self.cReader.getData(datagram):
					self.myProcessDataFunction(datagram)

But the reader crashes like this:

Assertion failed: connection->get_socket()->is_exact_type(Socket_TCP::get_class_type()) at line 169 of c:\buildslave\release_sdk_win32\build\panda3d\panda\src\net\connectionWriter.cxx
:thread(error): Exception occurred within PythonThread Thread-1
Traceback (most recent call last):
  File "C:\pascal\shimstar\ShimstarClient\shimstar\network\network.py", line 59, in run
    while self.cReader.dataAvailable():
AssertionError: connection->get_socket()->is_exact_type(Socket_TCP::get_class_type()) at line 169 of c:\buildslave\release_sdk_win32\build\panda3d\panda\src\net\connectionWriter.cxx

I don’t understand why?
Do you have any clue to help me?

Thanks a lot.

I’m not terribly familiar with Python networking (and indeed no networking expert by far), but it looks as though cReader is expecting a TCP connection, and you’re giving it a UDP connection. Are you sure that QueuedConnectionReader and in particular its method “dataAvailable” are both intended to be used with a UDP connection?

I saw nothing about that on the documentation.

Nevertheless, that seems to be the case. Take a look at this excerpt from your posted error:

connection->get_socket()->is_exact_type(Socket_TCP::get_class_type())

Or, as I interpret it to roughly be: “Is the connection’s socket a TCP socket?”

That said, I’m afraid that I should let someone else step in to provide more information – I really don’t know much about these classes. Hopefully someone else here is in a position to tell you what methods might be available to achieve what you intend.

Weirdly it seems that it is used, and shown on other thread:

[url]UDP]

But if someone can give more information on my mistake, I will be happy

For information, I create in another class, a TCP connection for reliable communication.
Is there conflict in queuedConnectionReader/Manager if there are two types of connection?

No idea?

This is from my udp reader.This is what i think you need i didnt really read the thread.

        while self.cReader.dataAvailable():
            datagram = NetDatagram()
            if self.cReader.getData(datagram):

I got this chunk of code in my example above.

It seems that the dataAvailable work only on a cReader typed TCP.

Traceback (most recent call last):
  File "C:\pascal\shimstar\ShimstarClient\shimstar\network\network.py", line 59, in run
    while self.cReader.dataAvailable():
AssertionError: connection->get_socket()->is_exact_type(Socket_TCP::get_class_type()) at line 169 of c:\buildslave\release_sdk_win32\build\panda3d\panda\src\net\connectionWriter.cxx

Ok I solved myself the problem.
In case of UDP, the rawmode must be put to 0 for the connectionReader and writer

self.cReader = QueuedConnectionReader(self.cManager, 0)
		self.cReader.setRawMode(0)
		self.cWriter = ConnectionWriter(self.cManager,0)
		self.cWriter.setRawMode(0)

In case of data send, (when you write), you have to add in the parameters the netadress

self.serverAddr = NetAddress() 
self.serverAddr.setHost(self.ip_address, 9097) 
self.cWriter.send(self.myNewPyDatagram(id,msg),self.myConnection,self.serverAddr)

Ah, I’m glad that you fixed it!

For what it’s worth I was in the process of posting the results of some digging, which seemed to point in much that direction, when I noticed that you had posted your solution in the meanwhile.

I’ll confess that I’m a little surprised that you haven’t had more replies – I imagined that there would likely be at least someone around who was familiar with this…

[edit]
For those who might come to this thread at a later point, it seems that ConnectionWriter has two “send” methods, one each for UDP and TCP, each with assertions that block use for the other type. The two methods, both named “send”, are differentiated by their parameters: the UDP version appears to take an extra “address” parameter (before the “block” boolean parameter).

Thanks.

In fact, I am not sure there are lot of people playing with network, and less using UDP…

The way I found the solution was to read the cxx code. It is very well commented.