Intermittent bind failure

I’m getting a bind error quite frequently on the ConnectPortX2 when executing the following code snippet

[pre]self.socket = socket(AF_ZIGBEE, SOCK_DGRAM, ZBS_PROT_TRANSPORT)
self.socket.bind((“”, 0xe8, 0, 0))


#> python
Traceback (most recent call last):
File “”, line 474, in ?
File “”, line 262, in init
File “”, line 1, in bind
socket.error: (22, ‘Invalid argument’)

I’m confident that nothing else is running, for example, here’s the CLI ‘who’ output immediately after getting the above bind error:

#> who

ID From To Protocol Sessions

1 local shell telnet

Bizarrely, if I run the program 2 or 3 times in a row, it will frequently work fine after initially throwing the socket error.

Any ideas? This is preventing my code from starting reliably in “run on boot” mode (currently deactivated).

The only way this error can be thrown is if the socket is already in use. Is it possible that the bind may be occurring twice in your code in some way?

Could you wrap your bind call in print statements to make sure?

Could you post a screen capture of the output of the “set python” command?


Actually, I believe it’s possible for this error to occur if the network subsystem of the device has not fully initialized as well. If the system is still going through DHCP negotiation for example. This seems to match the fact that it blocks startup, but can still be run manually.

It’s probably best to add a test try-except loop or an explicit startup delay for this call.