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

10 Ansichten (letzte 30 Tage)
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()
print(msg)
if msg == 'close':
conn.close()
break
listener.close()
Python client code :
from multiprocessing.connection import Client
address = ('localhost', 6000)
conn = Client(address, authkey=b'secret password')
conn.send('close')
# can also send arbitrary objects:
# conn.send(['a', 2.5, None, int, sum])
conn.close()
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 ?
  4 Kommentare

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Kategorien

Mehr zu Call Python from MATLAB finden Sie in Help Center und File Exchange

Produkte


Version

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by