Alex Rivera | Logout

What does it mean to flush a socket?

Asked 2009-05-27T06:41:36.913
29

I don't really know much about sockets except how to read and write to them as if they were files. I know a little about using socket selectors. I don't get why you have to flush a socket, what's actually happening there? The bits just hang out somewhere in memory until they get pushed off? I read some things online about sockets, but it's all very abstract and high level.

What's actually happening here?

Edit
Report

2 Answers

14

You can't really flush a socket.

(From How can I force a socket to send the data in its buffer?)

You can't force it. Period. TCP makes up its own mind as to when it can send data. Now, normally when you call write() on a TCP socket,
TCP will indeed send a segment, but there's no guarantee and no way to force this. There are lots of reasons why TCP will not send a
segment: a closed window and the Nagle algorithm are two things to
come immediately to mind.

Read the full post, it is quite in-depth and clarified a lot of things for me.

answered 2011-08-11T11:07:30.093
4

Nagle's algorithm is often in use on sockets. In a nutshell, it waits until there's a non-trivial amount of data to send. The problem is to achieve a balance between transmission latency and the overhead cost of sending a packet of data.

The larger the data payload, the smaller the wasted bandwidth because the header is of (mostly) fixed size. Furthermore intermediate systems generally have performance limits based more significantly on the packet-rate, not the overall data-rate.

answered 2009-06-06T14:36:03.290

Your Answer