Clear Filters
Clear Filters

How could a 'byte string' input argument be passed to a python function called from MATLAB ?

4 views (last 30 days)
I am trying to create a server-client application using ipc, where server is a pure Python application and client is a MATLAB application which calls python functions. I have Anaconda installed with Python 3.7 environment.
Python Server code :
from multiprocessing.connection import Listener
address = ('localhost', 6000) # family is deduced to be 'AF_INET'
listener = Listener(address, authkey=b'secret password')
conn = listener.accept()
print('connection accepted from', listener.last_accepted)
while True:
msg = conn.recv()
if msg == 'close':
Python client code :
from multiprocessing.connection import Client
address = ('localhost', 6000)
conn = Client(address, authkey=b'secret password')
# can also send arbitrary objects:
# conn.send(['a', 2.5, None, int, sum])
When executed in Python, the above pair is working fine.
Now trying MATLAB equivalent of above Python client code in command line :
>> mp_pyModule = py.importlib.import_module('multiprocessing.connection');
>> client_fn = mp_pyModule.Client;
>> address = py.tuple({'localhost',int16(6000)});
>> conn = client_fn(address,pyargs('authkey','secret password'));
Error using connection>Client (line 495)
Python Error: TypeError: authkey should be a byte string
I require the above argument 'secret password' to be sent as a 'byte string'. Is there any method ?
Unsupported types to Python does not mention anything about this. Is there any other limitation ?

Sign in to comment.

Answers (0)




Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!