Question

I have a problem. I have read a lot of topics on stackoverflow about this problem but nothing helped. I am trying to implement client-server communication via comet connection. I have an instance which is responsible for sending messges and instance which is responsible for receiving messages. The process is the following: - Send instance sends GET request to server, server responds to the receive instance. The first call works fine, I get the first response and can get the data I need but next request do not make my didReceiveData callback to trigger. But I see that the server has sent data, I see it in the server logs and I see it in wireshark at client machine. An interesting thing: the first response hadn't been making my callback to trigger before I added "content-length: 0" to response. Undocumented feature of NSUrlConnection? What else should I consider to make NSUrlConnection think the response is valid? Alternative: force to fetch data from socket, but I don't know if it possible with NSUrlConnection (man is mute about it)

persistent connection code:

  NSURL* requestUrl = [NSURL URLWithString:[[NSString alloc] initWithUTF8String:rq->url.c_str()]];
  NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:requestUrl   cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:600];
  m->connection = [[NSURLConnection alloc] initWithRequest:request delegate:request_delegate() startImmediately:NO];

  [m->connection scheduleInRunLoop:[NSRunLoop mainRunLoop]
                              forMode:NSDefaultRunLoopMode];
  [m->connection start];
Was it helpful?

Solution

nginx server needs to set header section "content-length" to something big, because client gets packets and increases the amount of bytes received and after receiving the amount of bytes set in header - it won't take any more responses. Omiting content-length section will block delegate calls. That was the reason

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top