1

I am new to Objective-C. I tried to create a client to talk with server. After stream setup, I have seen event (NSStreamEventOpenCompleted & NSStreamEventHasSpaceAvailable) for NSOutputStream, but nothing for NSInputStream. It can send data to server, and also it is able to get data read from server by directly read to the NSInputStream. However, the event for InputStream never triggered.

Here is the Stream setup code:

    CFReadStreamRef readStream;
    CFWriteStreamRef writeStream;
    CFStreamCreatePairWithSocketToHost(NULL, CFBridgingRetain(IP), port, &readStream, &writeStream);

    _rStream = (__bridge_transfer NSInputStream *)readStream;
    _wStream = (__bridge_transfer NSOutputStream *)writeStream;
    [_rStream setDelegate:self];
    [_wStream setDelegate:self];
    [_rStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
    [_wStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
    [_rStream open];
    [_wStream open];

Anything wrong with it?

max
  • 11
  • 2

0 Answers0