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>
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
as an inout argument to the function
(assuming Swift 2):
var readBufferRef: UnsafeMutablePointer = 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.