Single request to multiple asynchronous responses

和自甴很熟 提交于 2019-12-10 13:55:41

问题


So, here's the problem. iPhones are awesome, but bandwidth and latency are serious issues with apps that have serverside requirements. My initial plan to solve this was to make multiple requests for bits of data (pun unintended) and have that be how the issue of lots of incoming//outgoing data was handled. This is a bad idea for a lot of reasons, most obvious to me is that my poor database (MySQL) can't handle this very well. From what I understand it's better to request large chunks all at once, especially if I'm going to ask for all of it anyways.

The problem is now I'm waiting again for a large amount of data to get through. I was wondering if there's a way to basically send the server a bunch of IDs to get from the database, and then that SINGLE request then sends a lot of little responses, each one containing all the information about a single db entry. Order is irrelevant, and ideally I'd be able to send another request to the server telling it to stop sending me things because I have what I need.

I realize this is probably NOT a simple thing to do so if you (awesome) guys could point me in the right direction that would also be incredible.

Current system is iPhone (Cocoa//Objective-C) -> PHP -> MySQL

Thanks a ton in advance.


回答1:


AFAIK, a single request cannot get multiple responses. From what you are asking, it seems that you need to do this in two parts.

Part 1: Send a single call with the IDs.

Your server responds with a single message that contains the URLs or the information needed to call the unique "smaller" answers.

Part 2: Working from that list of responses, fire off multiple requests that run on their own threads.

I am thinking of this similar to how a web page works. You call the HTML URL in a web browser. The HTML tells the browser all the places/URLS it needs to get additional pieces (images, css, js, etc) to build the full page.

Hope this helps.



来源:https://stackoverflow.com/questions/4198287/single-request-to-multiple-asynchronous-responses

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!