I am designing a game server which would be used for Android terminals. I've been searching for products or frameworks to use for two-way socket communication but haven't found anything worth mentioning.

Simply, I want to implement the architecture below:

Server architecture

In other words, one TCP connection from the client to the server, and another from the server to the client, in order to avoid always having to be connected.

Just to be clear, my main aim is for the server to be able to send data to the client, without the client having to explicitly request it. I do not want the client to have to poll the server to see if there is any new data.

What combination of design strategies, network protocols, and/or products or frameworks (if any) would be appropriate for implementing this architecture?


1 Answer 1


The problem is that the client will often be behind a NAT/firewall, which means that the server can't initiate a TCP connection to the client, because the client doesn't have a globally routable IP address and/or because the firewall will block the unexpected incoming TCP packets coming from the server.

So that means that any TCP connection will have to be initiated from the client side. Once that is done, you have the option of leaving the TCP connection open indefinitely (which you don't want to do) or closing the TCP connection once any immediate business has been attended to (but that means that the client will need to connect again later to see if more updates have arrived in the meantime, which is polling, which you also don't want to do).

So you're kind of stuck. The only possible solution I can think of is to set up a number of proxy servers that are not behind firewalls/NATs, and have your Android clients persistently connect to them. The proxy servers can then forward requests on to your main server, and since you control the proxies, you can make sure the server is able to connect back to them as necessary. If you're lucky, somebody else has already set up a system like this and you can simply piggyback on it... perhaps this will do what you want.

  • +1 This is pretty much how games requiring this kind of connection work. Nov 6, 2011 at 6:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.