I want to send from the server (in java) two messages:
send: 0x01
Sleep: 5 seconds
send: 0x02
The client is an iPhone app, and sometimes, when the app is in background, it take 5-10 seconds to send server an ack, and TCP sends the first message AND the seconds message in ONE PACKET, it go’s as following:
Time 00:00:00 server sends 0x01 - and wait for ack
Time 00:00:05 server not received ack and it needs to send the second message, so the server send: 0x01 0x02
Then the client don’t know what this message mean, and sends FIN.
Any suggestions?
I’ve looked in this page to find any option to avoid this chaining. May be you will find something related for this issue.
Thanks in advance.
You should disable the Nagle algorithm using
Socket.setTcpNoDelay(true)TCP is a stream-orientated protocol, not message based. If your client app can’t cope with stuff arriving in “odd” chunks then you’re doing it wrong.