JugsteR
JugsteR

Reputation: 1174

Streaming data to response CFHTTPMessageRef possible?

I know it is possible to stream data to a CFHTTPMessageRef that is a request object, this can be achieved by using the method CFReadStreamCreateForHTTPRequest.

Is it possible to do the same with a CFHTTPMessageRef that is a response object?

What I want to happen is that I start a thread/operation (or similar) with two parameters. Parameter one is a request with a readstream to read the actual request. Parameter two should be a response with preferably a write stream to write your reply in.

Obviously I can do this using a readstream and a writestream directly, however then I'd manually have to format the request and response.

Is this possible using the CFNetwork classes?

Upvotes: 1

Views: 811

Answers (1)

Milad Rezazadeh
Milad Rezazadeh

Reputation: 1483

I didn't understand your question very well. but I used CFNetwork for my streaming. for receiving the response here is how I receive it:

-(void)stream:(NSStream *)aStream handleEvent:(NSStreamEvent)eventCode
{    
    /*
         The NSStreamEvent constant can be one of the following:
         NSStreamEventNone              -- No event has occurred.
         NSStreamEventOpenCompleted     -- The open has completed successfully.
         NSStreamEventHasBytesAvailable -- The stream has bytes to be read.
         NSStreamEventHasSpaceAvailable -- The stream can accept bytes for writing.
         NSStreamEventErrorOccurred     -- An error has occurred on the stream.
         NSStreamEventEndEncountered    -- The end of the stream has been reached. 
     */

    switch (eventCode) 
    {
        case NSStreamEventHasBytesAvailable:
            len = [(NSInputStream *)aStream read:buf maxLength:1024];
            if(len) {    
                //_data type is nsmutabledata
                [_data appendBytes:(const void *)buf length:len];
                int bytesRead;
                bytesRead += len;
            } else {
                NSLog(@"No data.");
            }
            break;
        case NSStreamEventErrorOccurred:

            break;
        case NSStreamEventOpenCompleted:

            break;
        case NSStreamEventEndEncountered:

            break;
        case NSStreamEventNone:

            break;
        case NSStreamEventHasSpaceAvailable:

            break;
        default:
            break;
    }
}

Upvotes: 1

Related Questions