套接字编程 - rajay

时间:2014-04-10 05:33:17

标签: sockets socket.io nsstream

使用下面提到的代码通过套接字编程从服务器接收数据。但接收不在这里。但服务器连接和发送数据工作正常。如何从服务器接收数据。

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

0 个答案:

没有答案
相关问题