openTCPClientConnection works even when no server available?

Hello, I am relatively new to python and Panda, and have been trying some of the examples from the manual. However, when I got to networking part, I noticed a strange behaviour. I have the client code that goes like the one in the manual:

		self.cManager = QueuedConnectionManager()
		self.cReader = QueuedConnectionReader(self.cManager, 0)
		self.cWriter = ConnectionWriter(self.cManager,0)
		
		ip_address="localhost" #tried with other random addresses, too
		port_address=9099 #No-other TCP/IP services are using this port
		timeout_in_ms=3000  # 3 seconds

		self.tcpSocket = self.cManager.openTCPClientConnection(ip_address, port_address, timeout_in_ms)
		
		if self.tcpSocket:
			print self.tcpSocket, "is active"
			self.cReader.addConnection(self.tcpSocket)  # receive messages from server
		else:
		   print "Could not connect to server."

I also have a server set up to listen at port 9099, and if both programs are executed, the server “sees” the client, and they can communicate with each other.
The funny thing is that if I run just the client without starting a server first (confirmed by no results from netstat -l | grep 9099), it doesn’t see any problem and still acts as if the server was there, giving me the message:

<libpanda.Connection object at 0x31343c8> is active

The client can also send messages through the connection, although obviously it does not receive any reply because the server does not exist.
Does anyone else have this problem? Or am I simply checking for connection in a wrong way?
In case it was related somehow to my operating system, I am using Ubuntu 9.10 with 2.6.31-23 kernel (x86_64), and a manually compiled panda3d-1.7.2(stable).
Any help would be greatly appreciated. Panda seems one of the nicest engines I have worked with so far and I would like to learn some more!

LAST MINUTE CHECK: the API reference states that “If the connection is not established within timeout_ms milliseconds, a null connection is returned”.
I still don’t know what a null connection is, though… Is null supposed to mean None here, kind of like NULL pointer in C++? Or do I still get a Connection object, but I have to check somehow if it is null or not? I tried:

tcpSocket.getSocket().Active()

but it still says True even when there is no server.

Oops, this is actually a bug. I’ve just committed a fix, which will be visible on the next buildbot release. The expected behavior is that openTCPClientConnect() will return None if the connection fails.

As a workaround, you can check tcpSocket.getSocket().GetPeerName().GetIPAddressRaw(), which will return zero in the case of a failed connection, and nonzero in the case of a successful connection.

David

Thanks for a quick reply, it works! :slight_smile: