Looking for CP4x socket advice / example program

I am working on my first python/connectport x4 project. The python code uses the Digi extensions to the socket library to collect serial data streams from a set of xbee enabled sensors. The CPx4 serial port outputs the collected data to a pc app. through the rs-232 serial port.

Now I would like to add the ability to replace the physical hardwired pc-serial port connection with a python “socket”. I believe this would allow the pc to talk to the CPx4 through the built in cell phone’s fixed IP addres rather than an RS-232 cable.

I have gotten the SMS, SMTP, and WEB interfaces working, but am stumped by the socket - socket software. The existing pc app is written in Visual C# 2008.

Am I heading in the right direction? Can I use sockets to talk from the pc app to the CPx4? Is there some example code that I could try?

Thanks in advance.

You could look at this code: http://www.digi.com/wiki/developer/index.php/UDP_to_XBee_Network

This is UDP, but TCP will not be much different. Not how you need to manage your own sockets in Python - the X4 cannot magicaly frontend this for you on say 2101, 2102, etc.

Thanks for the helpful link. I was able to instal and run the python code.

How do I connect to the UDP sockets that are created? I tried telnet with the appropriate port (4000-4002 in my case). I was able to complete the connection, but not able to do any sort of I/O with the socket.

Is there a tool out there that would allow me to connect to a UDP or TCP socket with some sort of a terminal? (This may be a foolish sounding question, but I am fairly new to python and CP4x).

For telnet you’ll need to modify the sampel to use TCP streams instead of UDP data grams. I think if you study real basic “Python UDp Socket Example” and “Python TCP Socket Example” on the web you can easily modify the code to use TCP instead of UDP. The ‘select()’ is the same, and I’d expect you only need to change a few calls without adding or removing any code.

I’m not sure why that sample is UDP, other than someone who triggered it wanted UDP.