I understand that. My question is whether it is possible to prevent
the client from trying to optimize the traffic by accumulating enough
data before it sends it? I've used other languages that allow you to
set a property to turn this off and have the data sent out as soon as
it's written to the socket, I believe it's called the Nagle algorithm?
So although it wouldn't necessarily be sending the data in the same
chucks as they are written, like UDP, it would be sending out data as
soon as it's written. So you may get some overlap between messages,
but overall the data being received would come in as fast as the
client was sending, instead of the client buffering enough data before
sending it. Is there a way to do that with this class? I've done it
with other languages.
Thanks for your help!
On Mar 17, 2:49 pm, Robert Hanson <
robbiehan...@deusty.com> wrote:
> I think, perhaps, you're a bit confused about what TCP is, and how it
> works.
>
> UDP has a concept of datagrams (packets). You send a packet, and the
> packet arrives on the other side. You send 3 packets, and 3 separate
> packets arrive on the other side.
>
> None of this is true for TCP. TCP has absolutely no concept of
> datagrams.
>
> TCP deals with only a single stream of data. TCP considers every
> single write call to be a smaller part of the larger stream.
> Therefore, it will combine your writes to maximize the data
> transmission rate.
>
> For example, say you do this:
>
> socket.write(msg1); // msg1 is 10 bytes
> socket.write(msg2); // msg2 is 20 bytes
> socket.write(msg3); // msg3 is 50 bytes
>
> (Notice this example was written in some other language like C. This
> is because the example is true of TCP regardless of which language
> you're writing your application in.)
>
> It is VERY likely that TCP will send a single "packet" that contains
> all 3 messages. So the other side will receive all 3 messages at
> exactly the same time.
>
> -Robbie Hanson
> -Deusty Designs
>