Python socket sending and receiving

Hi,

I’m trying to write a Python script that sends data over a vtk socket. I can’t work out how the Python bindings for the Send() and Receive() methods work. If I try and pass a python string as the first argument, I get “TypeError: Send argument 1: requires a _addr_p_void string”. If I try and pass anything else, I get “TypeError: Receive argument 1: object does not have a readable buffer”. I have similar problems with Receive(). How are these methods supposed to be used in Python?

On a related note, is there any documentation for the Python bindings (besides what’s written by the help() function)?

Thanks,
Tom

The Send() and Receive() methods need to be given a Python object that supports the “buffer protocol”, e.g. a python “bytes” object, a “bytearray” object, or a numpy array. The python buffer protocol is a set of C APIs that allows Python extensions like numpy or vtk to directly access the storage space that is used by a Python object.

A python string object (in Python 3, at least) does not support the buffer protocol, since the internal encoding of the string is private.

See the README for more info. The short story is, the Python wrappers provide a translation layer between C void * and the Python buffer protocol.

Thanks for your quick reply - it worked, but I still had problems. I dropped in to C++ to debug these problems, and I’ve ended up starting a new thread here: C++ Socket Problems