GCDWebServer for streaming
<p>I was trying to stream a mp4 video from a remote server on a iOS device. I somehow got 
<code>[ERROR] Error while writing to socket 15: Broken pipe (32)</code> after a few writes.</p>

<p>Not sure where is wrong. Can you kindly give any advice?</p>

<p><a href="https://stackoverflow.com/questions/33002143/ios-re-routing-requests-w-gcdwebserver-not-redirecting">iOS re-routing requests w/ GCDWebServer (not redirecting)</a></p>

<p>Thanks!
Rao</p>

<pre><code>@property (nonatomic, strong) GCDWebServerBodyReaderCompletionBlock cb;

[_webServer addDefaultHandlerForMethod:@"GET"
                         requestClass:[GCDWebServerRequest class]
                         processBlock:^GCDWebServerResponse *(GCDWebServerRequest* request) {

                             NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration ephemeralSessionConfiguration];
                             self.session = [NSURLSession sessionWithConfiguration:configuration delegate:self delegateQueue:[NSOperationQueue mainQueue]];

                             GCDWebServerStreamedResponse* response = [GCDWebServerStreamedResponse responseWithContentType:@"application/octet-stream" asyncStreamBlock:^(GCDWebServerBodyReaderCompletionBlock completionBlock) {
                                 NSString * realURL = @"https://ia800309.us.archive.org/2/items/Popeye_Nearlyweds/Popeye_Nearlyweds_512kb.mp4";
                                 self.cb = completionBlock;
                                 NSURLSessionDataTask * dataTask = [self.session dataTaskWithURL:[[NSURL alloc] initWithString:realURL]] ;

                             }];
                             return response;
                         }];

(void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask          *)dataTask
didReceiveResponse:(NSURLResponse *)response
 completionHandler:(void (^)(NSURLSessionResponseDisposition   disposition))completionHandler
{
    self.response = response;
    completionHandler(NSURLSessionResponseAllow);
}

(void)URLSession:(NSURLSession *)session dataTask:(NSURLSessionDataTask *)dataTask
    didReceiveData:(NSData *)data
{
     NSLog(@"got data size == %lu", data.length);
    self.cb(data, nil);
}

 (void)URLSession:(NSURLSession *)session task:(NSURLSessionTask *)task
 didCompleteWithError:(NSError *)error
 {
     self.cb([NSData data], nil);
 }


    [DEBUG] Did open IPv4 listening socket 6
    [DEBUG] Did open IPv6 listening socket 7
    [INFO] GCDWebServer started on port 8080 and reachable at http://192.168.1.27:8080/
    2016-02-23 15:34:39.096 Proxy2Proxy[5315:1148991] Visit http://192.168.1.27:8080/ in your web browser
    [DEBUG] Did open connection on socket 15
    [DEBUG] Did connect
    [DEBUG] Did start background task
    [DEBUG] Connection received 370 bytes on socket 15
    [DEBUG] Connection on socket 15 preflighting request "GET /https://ia800309.us.archive.org/2/items/Popeye_Nearlyweds/Popeye_Nearlyweds_512kb.mp4" with 370 bytes body
    [DEBUG] Connection on socket 15 processing request "GET /https://ia800309.us.archive.org/2/items/Popeye_Nearlyweds/Popeye_Nearlyweds_512kb.mp4" with 370 bytes body
    [DEBUG] Connection sent 175 bytes on socket 15
    2016-02-23 15:34:47.488 Proxy2Proxy[5315:1148991] got data size == 16059
    [DEBUG] Connection sent 16067 bytes on socket 15
    2016-02-23 15:34:47.488 Proxy2Proxy[5315:1148991] got data size == 32768
    [DEBUG] Connection sent 32776 bytes on socket 15
    2016-02-23 15:34:47.489 Proxy2Proxy[5315:1148991] got data size == 32768
    [DEBUG] Connection sent 32776 bytes on socket 15
    2016-02-23 15:34:47.489 Proxy2Proxy[5315:1148991] got data size == 98304
    2016-02-23 15:34:47.490 Proxy2Proxy[5315:1148991] got data size == 16384
    [DEBUG] Connection sent 98313 bytes on socket 15
    [DEBUG] Connection sent 16392 bytes on socket 15
    2016-02-23 15:34:47.506 Proxy2Proxy[5315:1148991] got data size == 16384
    [DEBUG] Connection sent 16392 bytes on socket 15
    2016-02-23 15:34:47.517 Proxy2Proxy[5315:1148991] got data size == 16384
    [DEBUG] Connection sent 16392 bytes on socket 15
    2016-02-23 15:34:47.530 Proxy2Proxy[5315:1148991] got data size == 16384
    [DEBUG] Connection sent 16392 bytes on socket 15
    2016-02-23 15:34:47.545 Proxy2Proxy[5315:1148991] got data size == 16384
    [ERROR] Error while writing to socket 15: Broken pipe (32)
</code></pre>