Created
April 3, 2013 13:27
-
-
Save moea/5301205 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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