Robospice pararell网络请求 - 在收到对之前的响应之前发出请求

时间:2014-04-25 14:53:19

标签: java android robospice ape

我正在为Android中的聊天编写APE协议的实现。在一种情况下,我需要发送一个请求,该请求保留在服务器上,直到我发送另一个请求(然后服务器返回对第一个请求的响应)。

如何使用Robospice正确执行此操作?我将库设置为使用2个线程,但它无法正常工作 - 一些首次请求工作正常,但经过一段时间后,Robospice说 - request added to queue但请求未发送。

我附上我的日志:

04-25 16:39:46.094  /com.xx.xx D/CHAT﹕ CHECK
04-25 16:39:46.184  /com.xx.xx D/CHAT﹕ SENDING: [{"sessid":"18c61b18e5a8ce1513e80b8b50c3d865","cmd":"CHECK","chl":3}]
04-25 16:39:56.094  /com.xx.xx D/CHAT﹕ CHECK
04-25 16:39:56.214  /com.xx.xx D/CHAT﹕ SENDING: [{"sessid":"18c61b18e5a8ce1513e80b8b50c3d865","cmd":"CHECK","chl":4}]
04-25 16:39:57.004  /com.xx.xx D/CHAT﹕ RECIVED: [{"data":{"code":null,"from":null,"msg":null,"pipe":null,"sessid":null,"user":null,"users":null,"value":"null"},"raw":"CLOSE","time":"1398436529"}]
// For now it works ok - I send first request, then after 10 secs I send another and get response to first
04-25 16:40:06.095  /com.xx.xx D/CHAT﹕ CHECK
04-25 16:40:06.305  /com.xx.xx D/CHAT﹕ SENDING: [{"sessid":"18c61b18e5a8ce1513e80b8b50c3d865","cmd":"CHECK","chl":5}]
04-25 16:40:07.036  /com.xx.xx D/CHAT﹕ RECIVED: [{"data":{"code":null,"from":null,"msg":null,"pipe":null,"sessid":null,"user":null,"users":null,"value":"null"},"raw":"CLOSE","time":"1398436539"}]
// Up I get response for second request
//From now I see that functions for starting request is launched, but no request is made
04-25 16:40:16.105  /com.xx.xx D/CHAT﹕ CHECK
04-25 16:40:26.124  /com.xx.xx D/CHAT﹕ CHECK
04-25 16:40:36.134  /com.xx.xx D/CHAT﹕ CHECK

我使用此代码执行第一个请求,然后开始循环以每10秒执行一次下一个请求:

check(); //does request
periodicCheck.postDelayed(periodicCheckRequest, 10000); //starts a loop

private Handler periodicCheck;
    private Runnable periodicCheckRequest = new Runnable() {
        @Override
        public void run() {
            check(); //does request
            periodicCheck.postDelayed(this, 10000);
        }
    };

为什么它没有按预期工作的任何想法?

0 个答案:

没有答案