Hello everybody.

 

I'm learning how to use Mina and my questions are:

 

I solved my problem of having a answer from my server without closing the
session like this:

 

System.out.flush();

 

Is that ok?

 

I'm receiving the answer in Android via GPRS like this:

 

First I set this on sessionCreated

session.getConfig().setReadBufferSize(16*1024);

 

@Override public void messageReceived(IoSession session, Object message)
throws Exception { 

                IoBuffer                              buffer
= (IoBuffer)                       message;

                int                                          service
= (Integer)                         session.getAttribute("SERVICE");

                Listener                               listener
= (Listener)                        session.getAttribute("LISTENER");

                String                                   data
= "";

                int                                          size
= buffer.getInt();

                while (buffer.hasRemaining()){

                               data += (char) buffer.get();

                }

                if(size == data.trim().length()){

                               if(listener != null)
listener.requisitionFinished(data, service);

                } else {

                               if(listener != null)
listener.requisitionFinished("", service);

                }

                Log.d("WEB", "SERVICE: " + service + " SIZE: " + size + "
DATA: " + data);

}

 

Sometimes I receive the data in parts, when the message arriving is too long
and it causes an error, even if the buffersize is bigger than the data I'm
receiving.

 

Thank's a lot.

 

Luciano Coelho

Reply via email to