java - Android-App consume to much energy. Sockets maybe the reason -


in app use datagramsocket, 1 serversocket , several sockets. when app runs on android-device, phone hot on 1 area , needs lots of energy. think reason problem sockets. im not sure opperation energy-consuming:

does cost energy create new sockets:

socket = new socket(); ss = new serversocket( port ); msocket = new multicastsocket( port ); 

is importand close serversocket , other sockets if don't need anymore.

does connecting cost energy?

so.connect( new inetsocketaddress(ip, port ), 1000); 

and after connecting connection need energy?(is better disconnect when don't send datas long time) high amount of sockets need energy?

i have several threads:

beside main-thread , 3 binderthreads, have 3 more:

1st thread: listen incoming message on datagram-socket:

datagrampacket packet = new datagrampacket(buffer, buffer. length); msocket .receive(packet); 

2nd thread: listen incoming messages on several sockets:

try {       if (objectinputstreamlist .size() != 0){             if (counter >= objectinputstreamlist .size()){                  counter = 0;              }              objectinputstream ois = objectinputstreamlist .get(counter);              object o = ois.readobject();              if (o instanceof message){                  receive((message) o);              system.out .println("message received in server");                  }              }      } catch (sockettimeoutexception sotoe){         counter++;      } 

3rd thread: send datas via http-request via internet server.

does 1 of threads need energy?

the app needs energy if wifi turned off or wifi turned on not connected wlan. , there no connections.

which of opperations energyconsuming? , can reduce energy?

thank answers.

given runs hot when it's not supposed anything, suspect 1 of threads running freely instead of blocking. can't tell more without complete source code, old printf debugging might come in handy. put different logging statements in each of while loops , run program. if statement fills log @ alarming rate, there have it.

yes should close socket no longer need. example, if don't close server sockets ports remain occupied. system run out of ports. (i come many other reasons, including resource usage , elegance. tidying things might make problem obvious.)

fyi having many sockets open not cost energy in , of itself. network activity costs little energy (pay attention idle timers!), shouldn't make 1 part of device hot.


Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

python - cx_oracle unable to find Oracle Client -