使用下面提到的代码通过套接字编程从服务器接收数据。但接收不在这里。但服务器连接和发送数据工作正常。如何从服务器接收数据。
case NSStreamEventHasBytesAvailable:
event = @"NSStreamEventHasBytesAvailable";
if (theStream == inputStream)
{
uint8_t buffer[1024];
int len;
while ([inputStream hasBytesAvailable])
{
len = [inputStream read:buffer maxLength:1024];
NSLog(@"buffer %s",buffer);
NSLog(@"Received data--------------------%d", len);
if (len >= 0)
{
NSMutableString *output = [[NSMutableString alloc] initWithBytes:buffer length:len encoding:NSUTF8StringEncoding];
NSLog(@"Received data--------------------%@", [output description]);
NSLog(@"buffer %s",buffer);
}
}
}