# Loopback in Python?

**URL:** <https://forums.digi.com/t/loopback-in-python/2700>\
**Category:** Python\
**Created:** [August 13, 2008, 7:46pm UTC](https://forums.digi.com/t/loopback-in-python/2700 "2008-08-13T19:46:10Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![MikeB](https://avatars.discourse-cdn.com/v4/letter/m/e95f7d/32.png) [@MikeB](https://forums.digi.com/u/MikeB)\
**Post date:** [August 13, 2008, 7:46pm UTC](https://forums.digi.com/t/loopback-in-python/2700/1 "2008-08-13T19:46:10Z")

</div>

Is it possible to do a loopback type of communication with python? I wanted to make sure that my code worked up to this point.

I tried:  
sd.sendto(“stuff”, 0, node0)  
payload, src\_addr = sd.recvfrom(72)

where node0 is the device itself, but this just blocks itself.  
-Mike

---

<div class="post-metadata">

**Author:** ![jordanh](https://avatars.discourse-cdn.com/v4/letter/j/74df32/32.png) [@jordanh](https://forums.digi.com/u/jordanh)\
**Post date:** [August 13, 2008, 7:50pm UTC](https://forums.digi.com/t/loopback-in-python/2700/2 "2008-08-13T19:50:29Z")

</div>

Can you provide a more complete code snapshot? What does your network look like? What devices do you have deployed?

---

<div class="post-metadata">

**Author:** ![MikeB](https://avatars.discourse-cdn.com/v4/letter/m/e95f7d/32.png) [@MikeB](https://forums.digi.com/u/MikeB)\
**Post date:** [August 13, 2008, 7:58pm UTC](https://forums.digi.com/t/loopback-in-python/2700/3 "2008-08-13T19:58:30Z")

</div>

The hardware I’m using is a Connectport X8 and a singular Xbee module in one of the dev boards.

I’m having trouble communicating across them so I wanted to test out just the simple communication snippets of code to make sure I was implementing them properly.

Its just a basic extension of zb\_ex2\_rw.py just in reverse. Where I do the following:

sd = socket(AF\_ZIGBEE, SOCK\_DGRAM, ZBS\_PROT\_TRANSPORT)

sd.bind((“”,0,0,0)) //using 0xe8 fails always

sd.sendto(“stuff”, 0, node0) //node0 is the Connectport X

payload, src\_addr = sd.recvfrom(72)

print payload  
print src\_addr

The only explicit change from the example code is in sd.bind((“”,0xe8,0,0)) to sd.bind((“”,0,0,0)) as the code always fails using 0xe8.

---

<div class="post-metadata">

**Author:** ![52637p](https://avatars.discourse-cdn.com/v4/letter/5/c6cbf5/32.png) [@52637p](https://forums.digi.com/u/52637p)\
**Post date:** [August 13, 2008, 8:08pm UTC](https://forums.digi.com/t/loopback-in-python/2700/4 "2008-08-13T20:08:18Z")

</div>

As bind problems have come up once or twice before, I’ll pose the common question: are any python scripts set to run at startup?

One can not bind to the same endpoint twice, so an existing, running script could cause a bind to fail.

The “who” command at the CLI can help determine whether there are running scripts.

The “set python” command can be consulted to determine whether any scripts are enabled to run at startup.

If you’ve already checked all of these things, and the bind continues to fail, it would be useful to start with the actual failure returned by the bind. That might indicate the necessary direction to be taken.

Message was edited by: 52637p

---

<div class="post-metadata">

**Author:** ![jordanh](https://avatars.discourse-cdn.com/v4/letter/j/74df32/32.png) [@jordanh](https://forums.digi.com/u/jordanh)\
**Post date:** [August 13, 2008, 8:31pm UTC](https://forums.digi.com/t/loopback-in-python/2700/5 "2008-08-13T20:31:01Z")

</div>

If you are using ZNet 2.5 or ZB modules you will have to bind to endpoint e8 _or_ change the DE parameter of your remote modules to 0.

I am guessing that your bind to e8 is failing because you have another Python application running concurrently when you are trying to bind to 0xe8. If you go to “Connections” on the Web UI do you see other Python threads running?

If you go to Python-\>Auto Start Settings is there a checkbox next to one or more script in that configuration area?

Jordan

---

<div class="post-metadata">

**Author:** ![MikeB](https://avatars.discourse-cdn.com/v4/letter/m/e95f7d/32.png) [@MikeB](https://forums.digi.com/u/MikeB)\
**Post date:** [August 13, 2008, 8:30pm UTC](https://forums.digi.com/t/loopback-in-python/2700/6 "2008-08-13T20:30:02Z")

</div>

It was odd in that the example code would work as long as it didn’t block and force me to hard reset the router. You were correct in that there was a script set to run at start up. I canceled that and now bind no longer fails at all.

I had read about some bind problems, but they all seemed to be related to Linux and what version of python you were using.

As someone unfamiliar with Python, and especially the TCP/socket stuff. I don’t completely understand what 0xe8 stands for. I read that it is the Maxstream serial data endpoint. So if I had to explain what I think is happening it would be: socket( … ) creates a sd class with all the socket methods, bind is a method that ties a specific data path to it, and then I just send/wait for data. Is that about correct?

Message was edited by: MikeB

---

<div class="post-metadata">

**Author:** ![MikeB](https://avatars.discourse-cdn.com/v4/letter/m/e95f7d/32.png) [@MikeB](https://forums.digi.com/u/MikeB)\
**Post date:** [August 13, 2008, 9:00pm UTC](https://forums.digi.com/t/loopback-in-python/2700/7 "2008-08-13T21:00:48Z")

</div>

Yup, that is why it was failing. I fixed that.

Unfortunately the program still blocks. So I guess that is not the way to do it?
