Skip to content

Instantly share code, notes, and snippets.

@moea
Created April 3, 2013 13:27
Show Gist options
  • Save moea/5301205 to your computer and use it in GitHub Desktop.
Save moea/5301205 to your computer and use it in GitHub Desktop.
import android.os.AsyncTask;
import android.os.Handler;
import org.jeromq.ZMQ;
public class ZeroMQMessageTask extends AsyncTask<String, Void, String> {
private final Handler uiThreadHandler;
public ZeroMQMessageTask(Handler uiThreadHandler) {
this.uiThreadHandler = uiThreadHandler;
}
@Override
protected String doInBackground(String... params) {
ZMQ.Context context = ZMQ.context(1);
ZMQ.Socket socket = context.socket(ZMQ.REQ);
socket.connect("tcp://127.0.0.1:5555");
socket.send(params[0].getBytes(), 0);
String result = new String(socket.recv(0));
socket.close();
context.term();
return result;
}
@Override
protected void onPostExecute(String result) {
uiThreadHandler.sendMessage(Util.bundledMessage(uiThreadHandler, result));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment