On Mon, Sep 2, 2013 at 5:37 PM, Luciano Coelho <luci...@lvcsistemas.com>wrote:

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


This really gives me an indication of your Java knowledge.  System.out is
your access to stdout in Java.  It is what you use to print things to the
console.  It has nothing to do with your application.

Maybe posting on StackOverflow would be a good idea for general java help?


>
>
>
> 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);
>
>
>
You should set this in Mina config.  It is not good to change on the fly
like this.

Read the Quick Start Guide:
http://mina.apache.org/mina-project/quick-start-guide.html


>
> @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();
>

Using the += is the worst possible way to build a String.

Since you are reading a String.  Are you sure that the String is encoded
using 8 bits?

byte[] payload = new byte[size];
buffer.get(payload);

String data = new String( payload, "UTF-8");



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

Why are you trying to trim the string?  Are you expecting whitespaces?


>
>                                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