let bufferSize = 4096
var buffer = Array<UInt8>(count: bufferSize, repeatedValue: 0)
var message = ""
while inputStream.hasBytesAvailable {
let len = inputStream.read(&buffer, maxLength: bufferSize)
if len < 0 {
BBLogError("error reading stream...")
return self.closeStreams()
}
if len > 0 {
// message += NSString(bytes: &buffer, length: len, encoding: NSUTF8StringEncoding) as! String
recivedData.appendBytes(&buffer, length: bufferSize)
message += NSString(bytes: &buffer, length: len, encoding: NSUTF8StringEncoding) as! String
}
if len == 0 {
BBLogError("no more bytes available...")
break
}
}
我的情况:服务器正在发送两个数据包。客户端如何知道服务器正在编写这么多数据包?