Reputation: 126165
Here's an extract of my code:
OutputStream out = this.socket.getOutputStream();
out.write(fourBytes);
out.write(someBytes);
out.flush();
This gets sent in 2 packages, even though the first one is only 4 bytes long. Is there another way than concatenating the byte arrays together to send them together?
I've already tried setTcpNoDelay(false)
.
Upvotes: 3
Views: 1069
Reputation: 223173
Sure. Use a BufferedOutputStream
. :-P
The setTcpNoDelay
changes how the OS sends packets, not how Java sends packets. The only way to change the latter is to buffer your output, as I suggested above.
BTW, this doesn't affect how many packets your data is really split up into. Again, that is up to the OS, as well as the window specified by the receiving end. So you can't use packets to delimit data.
Upvotes: 3