Are NSStreams or the sockets they use buffered?

  • I am using NSStream's getStreamsToHost:port:inputStream:outputStream:
    and sending data over the outputStream to send a file to the receiving
    client.

    --- DETAILS ---
    On my end, I implement my own buffering in case the packet of data
    that I'm sending can't all be accepted by the recipient. However, if
    another packet of data is "sent" but there is still data queued up,
    I'm queue up this new data elsewhere and waiting for the send queue to
    be emptied.

    It may sound a little complicated, but the reason I'm doing it this
    way is because the data is originally tagged with notification
    information and only when the data is actually sent using
    NSOutputStream's write:length: do I post the notification which will
    let me know how much data has been sent thus far. So the backup queue
    can hold the notification information, but the actual send queue is
    just NSMutableData.

    Anyway, even if you don't understand the above, the bottom line is
    that I'm trying to send data with as small a buffer as possible so
    that I'm sending data closer to real-time. This is because the
    receiving client will not send any notification that it has received
    the file until it has received the complete file.
    --- END DETAILS ---

    The end result at the moment is that on my side the file appears to be
    completely sent way before the receiving end gets the complete file.
    So I am wondering if the underlying socket connection that the Cocoa
    framework uses is buffering my data.

    Additionally, I am capturing NSStreamEventHasSpaceAvailable event
    codes and I only send data based on this. So does this event code mean
    that the socket can accept more data -- and possible not yet send it
    so it'll buffer it --- OR does it mean that the receiving end of the
    socket can really accept more data?
  • On 9 Jan 2008, at 17:02, Ryan Homer wrote:

    > The end result at the moment is that on my side the file appears to
    > be completely sent way before the receiving end gets the complete
    > file. So I am wondering if the underlying socket connection that the
    > Cocoa framework uses is buffering my data.

    If it's a TCP socket, a certain amount of buffering might happen,
    yes.  If you're trying to do real-time communication over TCP, you may
    want to set the TCP_NODELAY option.

    Kind regards,

    Alastair.

    --
    http://alastairs-place.net
previous month january 2008 next month
MTWTFSS
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31      
Go to today