Search code examples
javaandroidsocketsminaandroidasync-koush

reading data from socket - no performance


I am creating an android service which is always running and listening messages from socket. But it doesn't work with good performance and i am looking for some nio alternative or tutorial.

What is the best way for listening a socket for all time ?

Does AndroidAsync support standart sockets ? https://github.com/koush/AndroidAsync

Is there anyone used Apache Mina ? I am having character problem with Mina. http://mina.apache.org/

Or how can i do this job with good performance using standart sockets

Waiting for your experiences.

Thanks


Solution

  • The normal way to get decent performance from a socket (for int read() and write(int)) is to use a buffered stream / reader / writer. That reduces the number of system calls and makes byte or character at a time I/O much faster.

    I don't expect that using NIO will make a significant difference. If the problem is not buffering, then (IMO) it is probably a network bandwidth and/or latency issue. If that is the case, there is little that you can do in Java that would make much difference.