客户端如何知道服务器正在发送一些X字节?

时间:2016-02-26 20:48:07

标签: ios swift bonjour nsstream

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
                }
            }

我的情况:服务器正在发送两个数据包。客户端如何知道服务器正在编写这么多数据包?

0 个答案:

没有答案