Multiple HTTP requests vs a single TCP connection

2019-04-14 05:52发布

问题:

I am developing an iPhone app that uses a web based API that I control. Would it be faster or more efficient to connect to a constantly open TCP port and make requests via the TCP API, or make a new HTTP request for all the data that I want to fetch?

I am imagining that the different would be negligible, but I could be wrong.

New data is fetched pretty much every time a new view is loaded, so requests can happen fairly frequently.

回答1:

I think the difference would be minimal.

It is also worth noting that NSURLConnection supports the HTTP Keep Alive connections by default, so you could go straight HTTP and make sure your server is allowing the client to keep the connection alive.