0

I am writing an Android application that receives a continuous stream of data. I've set up the connection inside a runnable like so:

Runnable runnable = new Runnable()
    {
        public void run()
        {
        ZMQ.Context context = ZMQ.context(1);
        ZMQ.Socket subscriber = context.socket(ZMQ.SUB);
        subscriber.connect("tcp://[IP]:[Port]");
            TextView strDisplay = (TextView) findViewById(R.id.stringDisplay);
            while (!Thread.currentThread ().isInterrupted ())
            {
                // Read message contents
                Log.i("Output", "the while loop ran up to here");
                //*HANGS ON THE LINE BELOW*
                String testcase = subscriber.recvStr(0);
                strDisplay.setText(testcase);
                Log.i("Output", "The while loop completed");
            }

Now, after much scouring of the interwebs, I've come to two conclusions:

1) that recvStr() is a blocking call that waits until it receives something. So that means it hasn't connected properly or something else

and

2) that I may have to set up a filter of some sort?

I can't figure out what I should do next. Any help from someone experienced with JeroMQ or Android server access is greatly appreciated

AreM
  • 97
  • 10
  • Are you using `new Thread(runnable).start()` further down in the code? If you're not, then you're on the UI Thread and that's blocking the app right there. If you are, then you can't be using `findViewById()` and all that stuff, because these methods should only ever be used on the UI Thread. Check out `AsyncTask` and its `publishProgress()` mechanism for getting stuff from the background thread onto the UI Thread, or use a `Handler` on the main Looper. – Barend Jul 21 '15 at 19:45
  • @Barend yes, I have used `Thread connect = new Thread(runnable); connect.start();` and `findViewById()` actually does work here. But these aren't the issues at the moment. I just know that the `recvStr()` line is hanging everything up and I want to fix that first before formalities. – AreM Jul 21 '15 at 20:27

1 Answers1

1

Possibly, you need to subscribe on topic you want to get from publisher or to subscribe on all topics after you made connection.

For example subscribing on single topic:

subscriber.subscribe("topic_to_get".getBytes());

Subscribing on every topic:

subscriber.subscribe("".getBytes());
DontPanic
  • 1,327
  • 1
  • 13
  • 20
  • I did solve this afterwards, and this is the correct answer. This is what I meant by "setting up a filter" as a possible issue. – AreM Aug 03 '15 at 20:52