0

So, I have an application that communicates with a server quite frequently. I have the Socket creation done in a singleton class, to ensure that the work to create it is only done once. However, this is an Android application, and I can never guarantee that the code that cleans up when the application is destroyed will be executed. Therefore, I am currently opening and closing the socket every time I use it.

I have no idea how cpu intensive this is though, can anyone shed some light?

providence
  • 29,135
  • 13
  • 46
  • 62
  • 4
    I can tell you that power wise cpu time is cheaper than network connectivity on a mobile device. – Vetsin Apr 04 '11 at 18:09

1 Answers1

4

@providence, if it is a single application which opens/closes the sockets everytime it is used, from a CPU workload standpoint, it is not something I'd worry too much about. If you have an option of keeping the socket open, they might actually be a better thing to do. Mobile data connection options s.a. GPRS, EDGE, 3G-UMTS etc., have optimizations built-in, which relinquish wireless network bandwidth when not in use, and may even enter low-power state. Only when there is some data to be received or sent, does the phone come back to it's operating-power mode, and allocated wireless resources to the socket. All that your dormant socket is doing is consuming some memory.

PS> Having no first hand experience in doing network programming (directly at socket level) on Android, much of what I wrote is based on knowledge of wireless network technology, and general unix socket communication fundamentals :-).

Only if you like my answer, and find it useful feel free to vote it up.

mike.dinnone
  • 732
  • 2
  • 8
  • 17