Search code examples
iphonetcpconnectionchatbattery

Will the iPhone battery affected with an open TCP connection and not sending or receiving data?


Im currently developing a chat client for the iphone. Server-side there is a node.js with Socket.IO and on the iPhone an Socket.IO client ( https://github.com/DanLite/socket.IO-objc )

My Question is: Will the iPhone battery affected with an open TCP connection and not sending or receiving data for like 3-4 Minutes?

What is better for battery life? A constant tcp connection or multiply HTTP requests.

Thanks

Edit: I have a chat + other functions like (changing name, checking friends status, edit settings)

Edit 2: Looks like WhatsApp doing it with a tcp connection


Solution

  • When TCP connection is opened both parties posses information about it (remote ip:port, local ip:port). That information is a mere data structure in the memory. As long as there is no RST packet received or timeout occurred connection is considered to be opened.

    When you send data over connection you start consuming CPU and force underlying wireless mobile network module to send signal hence consume battery.

    That is why it is better to keep TCP connection for as long time as possible and prefer batching over chatty communication (combine several application messages).

    On the other hand you should be prepared to the situation when network coverage is poor and you will have to constantly reopen TCP connection thus consume battery.