How to use jeromq in MATLAB

2020-03-31 04:33发布

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?

标签: matlab jeromq
3条回答
SAY GOODBYE
2楼-- · 2020-03-31 04:49

My Matlab 9.0.0.341360 (R2016a) wanted the following code instead of import above:

javaclasspath('/path/to/jar/jeromq-0.4.3-SNAPSHOT.jar')
import org.zeromq.*

The rest worked fine.

查看更多
甜甜的少女心
3楼-- · 2020-03-31 04:53

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()
查看更多
Emotional °昔
4楼-- · 2020-03-31 04:58

Here is what I had to do to get things working.


    javaclasspath('jeromq-0.5.1.jar')
    import org.zeromq.*;

    %subscribe to ZMQ feed
    context = ZContext();
    socket = context.createSocket(ZMQ.SUB); 
    success = false;
    while(~success)
        success = socket.connect('tcp://127.0.0.1:5996');
    end
    socket.subscribe("");
    socket.setTCPKeepAlive(1);

    %receive a message
    message = socket.recv(0); %nonblocking receive uses argument (1)

    %when done
    socket.close();

查看更多
登录 后发表回答