我正在编写一个接收连续数据流的Android应用程序。 我已经成立了像这样内可运行的连接:现在Android应用程序挂在subscriber.recv()
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");
}
,在interwebs的多冲刷后,我得出两个结论:
1)recvStr()是一个阻止等待收到内容的电话。因此,这意味着它已经连接不正确或别的东西
和
2),我可能要建立某种形式的过滤器?
我不知道我应该接下来做什么。从别人的帮助经历了JeroMQ或Android服务器访问是极大的赞赏
您是否使用'新主题(可运行)。开始()'进一步代码下来?如果你不是,那么你在UI Thread上,这就是在那里阻止应用程序。如果你是,那么你不能使用'findViewById()'和所有这些东西,因为这些方法只能用在UI线程上。看看'AsyncTask'及其'publishProgress()'机制从后台线程获得的东西,到UI线程,或在主尺蠖使用'Handler'。 – Barend
@Barend是的,我用'Thread connect = new Thread(runnable); connect.start();''和'findViewById()'实际上在这里工作。但目前这些并不是问题。我只是知道'recvStr()'行已经挂起了一切,我想在手续之前先解决这个问题。 – AreM