0

我有奇怪的问题

服务器发送功能

-(void) writeToServer:(const uint8_t *) buf {
    NSLog(@"sending buf %s with lenght %zd", buf, strlen((char*)buf));
    [oStream write:buf maxLength:strlen((char*)buf)]; 
     // NSOutputStream *oStream
}

buf

NSLog(@"converted %@ length %d", encrypted, [encrypted length]);
// encrypted is NSMutableData
return (const uint8_t*)[encrypted bytes]; 

输出

 converted <4b010000 00000006 00000000 00000f20 30303031 4e50> length 22
 sending buf K with lenght 2

我需要 buf 保持不变.. 具有相同的原始字节和适当的长度,我应该怎么做?

4

1 回答 1

1

直接传入NSData对象:

-(void)writeToServer:(NSData *)data
{
    NSLog(@"sending with length %lu", (unsigned long)[data length]);
    [oStream write:[data bytes] maxLength:[data length]]; 
}
于 2013-01-23T07:58:48.580 回答