Size of the NSInputStream buffer

后端 未结 1 1053
再見小時候
再見小時候 2021-01-22 04:02

I\'m trying to use NSInputStream for receiving data using TCP socket connection. On the server side I send data size before sending of the data itself

相关标签:
1条回答
  • 2021-01-22 04:23

    In your code, readBufferRef is defined as a "pointer to a pointer" but never allocated, and therefore it is the NULL pointer.

    What you should do is to pass the address of an UnsafeMutablePointer<UInt8> as an inout argument to the function (assuming Swift 2):

    var readBufferRef: UnsafeMutablePointer<UInt8> = nil
    var readBufferLengthRef = 0
    let readBufferIsAvailable = inputStream.getBuffer(&readBufferRef, length: &readBufferLengthRef)
    

    On return, readBufferRef is set to the read buffer of the stream (valid until the next read operation), and readBufferLengthRef contains the number of available bytes.

    0 讨论(0)
提交回复
热议问题