Search code examples
matlabjeromq

How to use jeromq in MATLAB


jeromq is a Java implementation of libzmq. I have a .jar file created from the jeromq source. However, I'm unable to call a class in jeromq from MATLAB. I've used addjavaclasspath and addjavalibrarypath but am still not able to get it working. Does anyone have a simple working example in MATLAB?


Solution

  • I've added the answer here as for reference in case anyone else is interested.

    % Author : Dheepak Krishnamurthy
    % License : BSD 3 Clause
    
    import org.zeromq.ZMQ;
    
    ctx = zmq.Ctx();
    
    socket = ctx.createSocket(ZMQ.REP);
    
    socket.bind('tcp://127.0.0.1:7575');
    message = socket.recv(0);
    json_data = native2unicode(message.data)';
    
    message = zmq.Msg(8);
    message.put(unicode2native('Received'));
    socket.send(message, 0);
    
    socket.close()