[JAVA] Android TCP client

About socket communication on android. Currently, from the android terminal, the sensor value is set every 100ms I'm writing a program to send over TCP The transmission speed differs depending on the processing method.

Process 1. Divide into a connection request loop and a data transmission loop. Connect to the server with a connection request loop, (soket _soket = new soket(ipaddr,portno);) Instantiate outputstreamwriter and bufferwriter when connection is completed Send loop transition Write-> flush-> sleep (100) in send loop Repeat only the send loop.

Integrate the two loops of process 2 and process 1 Connect to the server, Instantiate outputstreamwriter and bufferwriter when connection is completed write -> flush -> close() -> sleep(100) Repeat from connecting to the server.

In the case of process 1, the transmission cycle is 300 ms In case of process 2, transmission cycle 100ms (possible up to almost the same time as the ping response)

Sorry for the rough explanation If you have any questions, we are looking forward to hearing from you.

The number of transmitted data is 10 bytes The server side is a socket debugger The transmission status is Wireshark I'm checking with.

Recommended Posts

Android TCP client
Android view