Pergunta

I'm developing an none market appliction which run on 20-30 android devices (target specific to tablets with android honeycomb / ICS OS) maintaining connection over local WIFI network for a 1-2 hours period of time, and need to exchange data (simple objects representing commands) between them.

most of the time one specific tablet behave like a server which sending the commands, and the other devices like clients which receives the commands, but the "clients" also sending commands to the "server" sometimes.

as solution to this communication demand - I'm using for a while an open source
library which encapsulates TCP client/server protocol, called - Kryonet. I found it very easy to use, and basically doing the job, although it sometimes "unstable" - a lot of disconnections accrues. I can't afford this disconnections, it's dammege the whole flow and use-case, causing the client's to lose commands.

I'm doing some recovery logic which re-connect the clients and send them what they have missed, but it's not good enough for the use-case.

recently I've heard about multicast broadcast protocol, and found even an open source library calls - JGroups which implement this protocol optimally, and expose easy and simple to use interface. still didn't tried it, but got advice from someone who knows, saying it should be better the the TCP client/server for my purpose.

  • what is the best approach I should use for implement the behavior I described ? (not necessarily one of the two I suggested)

TIA

Foi útil?

Solução

Although JGroups has promise as a better solution for your situation, you may want to experiment a bit more to determine why the disconnects are happening. Since your clients and server are all tablets, there are a few other causes that are unrelated:

1) If the connections are not being maintained in a Service then they will be extremely unreliable by default. (See this question about singletons being destroyed in Android)

2) If the sockets have not been set to 'keepalive' then they will time out after an arbitrary number of seconds.

3) The devices you are using may shut down some persistent connections when they go to sleep.

4) The tablets may be exiting WiFi range, and switching over to a mobile network.

Try the network portion of your code on a number of desktop machines to determine if the problem is with Kryonet or your code, or if the problem is in running it on Android.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top