I’m making an application for android that communicates with a server to control it by sending JSON strings. At the moment they communicating through sockets and the connection is constant, both the client and the server stay connected waiting for messages.
At the moment I am doing this to receive data on both the server and the client.
while ((input = in.readLine()) != null) {
System.out.println(input);
}
Is this a strain on battery life? Would it be better if the server running on the server was more like a web server – such that you connect, get the data then disconnect.
The problem is, I also need streaming data for things like chat. Which wouldn’t work to well with a setup like that.
Basically, is it a massive strain on the battery to keep a tcp socket connection open with a server? and… With streaming data such as chat, when the device goes to sleep – would it be best to drop the connection and keep a buffer of data on the server ready to send to the client when it reconnects?
More Basically, Best way to send streaming data while not depleting the battery?
EDIT: The application is a wrapper around a game server to control it.
For chat, I recommend using XMPP protocol. You’ll need to set up a server that with this and then use something like the Smack XMPP client library in your app.