Send data to socket without delay

  • Replies:2
adko dobro
  • Forum posts: 2

Mar 4, 2014, 12:00:33 PM via Website

I have next problem in developing app for android (Android studio, 4.0.3 kernel),

I communicate with my device over wifi. I need send from ever 20ms some bytes to my device. But I cannot send data more quickly like 100ms! When I use timer with 20ms period, system will send data in 100ms together. Setting timer to 200ms works, data sent ever 200ms. But In decreasing period to 20ms.

This is part of code:

// initialization of socket:

SocketAddress sockaddr = new InetSocketAddress(ip, parseInt(prt));
nsocket = new Socket();

//nsocket.setPerformancePreferences(0,1,2);
nsocket.setSendBufferSize(13);
nsocket.setTcpNoDelay(true);

// this is from timer, run every 20ms

nos = nsocket.getOutputStream();
nos.write(cmd);
nos.flush();


But android will send it with 100ms period! and together all bytes from every 30ms period of my timer

I think, it causes naggle algorithm. It's possible to switch it off. I found in documentation somethink about TCP_NODELAY, how can I use it? Is there any way how to send data to socket from android immediatelly?

Reply
adko dobro
  • Forum posts: 2

Mar 4, 2014, 12:35:32 PM via Website

yes, I read it, but I don't know how to use the TCP_NODELAY. here is more info: http: // developer.android.com/reference/java/net/SocketOptions.html
Any piece of code example will help me ...

Reply