0

I am writing an implementation of APE protocol for chat in Android. In one case I need to send a request, which is kept on server until I send another request (and then the server returns response to the first request).

How can I properly do this operation using Robospice? I set up the library to use 2 threads, but it does not work properly - a few first request work well, but after some time it Robospice says - request added to queue but the request is not send.

I attach my log:

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

I use this code to do first request and than start a loop to do next request every 10 seconds:

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);
        }
    };

Any ideas why it does not work as expected?

marcinm
  • 281
  • 1
  • 2
  • 11
  • I think you could try having 2 `SpiceManager`s, one for normal requests, and another for requests that must be executed in a different queue (not wait for normal requests to finish). – Hassan Ibraheem Apr 26 '14 at 08:56
  • I thought about it, but when I have 2 SpiceManagers binded to the same service - don't they use the same queue for requests? – marcinm Apr 26 '14 at 09:02
  • Not sure, I only tried it with different services, but you're probably right. You can just create another service, that extends your original service, just to make sure another instance is managed. – Hassan Ibraheem Apr 26 '14 at 09:14

0 Answers0