Vote count:
0
I have a PHP server that looks similar to this one:
header('Content-Type: text/plain; charset=utf-8');
header('Content-Encoding: none;'); //disable apache compressed
ob_end_flush();
ob_start();
set_time_limit(0);
error_reporting(0);
while(true){
echo ++$i.PHP_EOL;
ob_flush();
flush();
usleep(250 * 1000);
}
This server never closes the connection, and flushes an incrementing number every quarter second. When opening this page in a browser, it works fine, and the content grows while the page is still loading. This page is served via HTTP.
ATTEMPT #1, STRONGLY PREFERRED TO GET TO WORK
I also have a class that is an NSURLConnection with a timeout set to 0 (it shouldn't have a timeout at all). That class gathers data using the NSURLConnectionDelegate
protocol; whenever the server sends data, the function - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
is fired. This works excellently after a connection is closed; if there is a lot of data to be sent, one can track the progress very accurately.
In my case, however, the connection is not closed, and it never will be. Nevertheless, I would like to be notified of each flush. Currently, no method fires at all. The moment I set the PHP script to terminate after a certain period of time, and the connection closes, the data-received method is fired.
Therefore I was wondering: is there a way to be notified about every data transmission?
ATTEMPT #2
My next attempt was using NSInputStreams. I initiated them thus:
self.iStream = [[NSInputStream alloc] initWithURL:[NSURL URLWithString:@"http://localhost/secuchat/lab/socket_test.php"]];
[self.iStream setDelegate:self];
[self.iStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[self.iStream open];
Yet alas, here, too, the function - (void)stream:(NSStream *)aStream handleEvent:(NSStreamEvent)eventCode
is never fired.
Lastly, I would really prefer to somehow get it to work using the first method, for I would like to be able to send some data using POST, and raw sockets would make it much more difficult as opposed to libraries that already offer that function.
Aucun commentaire:
Enregistrer un commentaire