Read and Write Socket


I have connected two PC’s with two different ZNET 2.5 modules via serial port. I want to read whatever I am writing on the serial port of one PC and write it exactly on the other PC. Using the python manaul, I have written the following code,

from socket import *

The Format of the tuple is:

(address_string, endpoint, profile_id, cluster_id)

The values for the endpoint, profile_id, and

cluster_id given below are the values used to write

to the serial port on an Ember-based XBee module.

0xe8, 0xc105, 0x11)
0xe8, 0xc105, 0x11)

Create the socket, datagram mode, proprietary transport:


Bind to endpoint 0xe8 (232):

sd1.bind((“”, 0xe8, 0, 0))
sd2.bind((“”, 0xe8, 0, 0))
payload, SOURCE = sd1.recvfrom(72)
sd2.sendto(payload, 0, DESTINATION)

On running the code I am getting socket.error: (22, ‘invalid argument’). Please tell me what I am doing wrong here.


Socket error 22 means that the endpoint is already in use. Please verify that you are not already running an application using this endpoint.

You may telnet to the device and type “who” to see what is running. If you see any Python threads, either use the “set python” command or Navigate to the Python section of the Web-UI, then Auto-Start Settings, and disable the application from starting on boot up. Reboot and try your application again!


I’ve also seen the error 22 appear when the CP-X gateway can’t talk to one of the devices associated with it. If you power off the device which the CP-X can’t talk to, this error should go away.

Hi, I’ve read on the wiki site than one cannot bind to multiple socket, see:

The error is the same: 22, ‘invalid argument’.

Hope this can help

Hey i’m trying to do the same thing as ummi here.
I’ve got connectport X2 and 2 endpoints each connected to a pc (znet2.5 router/end device xbp24-b firmware version 1241 on both, but one is connected via usb and the other via rs232) . My only problem is that i dont know what application to use in order send/receive data from the pc’s. Sorry, but i’m all new to this. I know i have to write a program and upload it to the gateway to do this, but what application on the 2 pc’s do i use to be able to send data wirelessly from one pc to another via the xbee interface boards? If i can get the answer to this, i’ll probably understand why some of my code isnt working.

p.s. if anyone has any sample codes that do the same thing and works, i’d really appreciate if you could post it up please.

Thank you…

But I do not understand by,
“If multiple running applications do need to have access to the mesh socket, a locking mechanism of some sort would have to be used, similarly to if both applications shared a serial port.”*

Any advice would be helpful.


*Retrieved from “