3

I have implemented a program to communicate http2 using NSURLSession of iOS9, And it can communicate with my server in http2. However, I'm having a problem with receive server_push. I found ENABLE_PUSH value is 0 in their settings and there's no delegate in receive server push in NSURLSession...

・I think NSURLSession doesn't support server_push. Is this right?

・If it support server_push,how to use?

/**
It WORKS for post data and get response.
I don't know the code should be added here 
in order to get the server_push.
I suspect that NSURLSession itself cannot receive the server_push(;_;)
**/
- (void) postData
{
     NSString *urlstr = self.urlArea.text;
     NSURL * url = [NSURL URLWithString:urlstr];
     NSDictionary *params = @{@"data":@""};
    //json to query
    NSData *query = [self buildQueryWithDictionary: params];

    //make request
    NSMutableURLRequest *request = [NSMutableURLRequest
                                requestWithURL:url
                                cachePolicy: NSURLRequestReloadIgnoringCacheData
                                timeoutInterval: 10.0];
    [request setHTTPMethod: @"POST"];
    [request setHTTPBody: query];

    //prepare session
    NSURLSession *session = [NSURLSession sessionWithConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration] delegate:self delegateQueue:[NSOperationQueue mainQueue]];

    //resume
     [[session dataTaskWithRequest: request  completionHandler:^(NSData *data, NSURLResponse *response, NSError *error)
    {
        if (response && ! error) {
             NSLog(@"Data: %@", [[NSString alloc] initWithData: data  encoding: NSUTF8StringEncoding]);
        }else {
            NSLog(@"ERR: %@", error);
        }
    }] resume];
}
Community
  • 1
  • 1
t_ms
  • 130
  • 1
  • 12

2 Answers2

0

I read this here:

The HTTP2 push mechanism is not a generic server push mechanism like websocket or server sent events.

It is designed for a specific optimisation of HTTP conversations. Specifically when a client asks for a resource (eg index.html) the server can guess that it is going to next ask for a bunch of associated resources (eg theme.css, jquery.js, logo.png, etc. etc.) Typically a webpage can have 10s of such associated requests.

With HTTP/1.1, the server had to wait until the client actually sends request for these associated resources, and then the client is limited by connections to only ask for approx 6 at a time. Thus it can take many round trips before all the associated resources that are needed by a webpage are actually sent.

With HTTP/2, the server can send in the response to the index.html GET push promises to tell the client that it is going to also send theme.css, jquery.js, logo.png, etc. as if the client had requested them. The client can then cancel those pushes or just wait for them to be sent without incurring the extra latency of multiple round trips.

ere is a blog about the push API for HTTP2 and SPDY in jetty: https://webtide.com/http2-push-with-experimental-servlet-api/

Community
  • 1
  • 1
Suraj Sukale
  • 1,778
  • 1
  • 12
  • 19
  • Thank you for your information! Could you tell me if you know NSURLSession support this or not? – t_ms May 24 '16 at 08:39
  • yes.....and The HTTP/2 support is part of iOS 9, and thus won't be available on earlier OS releases. – Suraj Sukale May 24 '16 at 09:19
  • Hmm...I can see that only iOS9 (or later ) supports Http/2... but I dont know Whether iOS9's cocoa API have the function of SURVER_PUSH...> – t_ms May 25 '16 at 00:14
0

Solved

I received following reply from support.

iOS does not currently support this.


update

(@vin25 comment)

ios10 supports it.

t_ms
  • 130
  • 1
  • 12
  • Any update on this? Has support for this been added to iOS 10? – vin25 Oct 12 '16 at 10:17
  • 1
    Found out recently that iOS 10 does support it. Refer to the WWDC 2016 video on NSURLSession- https://developer.apple.com/videos/play/wwdc2016/711/. I have tested it and its working great! – vin25 Nov 28 '16 at 14:38