开发者

How does iphone apps interact with server?

开发者 https://www.devze.com 2023-01-07 08:04 出处:网络
I am a new programmer who is new to iPhone development and server stuff.I have a lot of questions to ask.

I am a new programmer who is new to iPhone development and server stuff. I have a lot of questions to ask.

You don't have to answer all the questions; any help is appreciated!

  1. How does iPhone apps interact with server?
  2. Is there a particular kind of server i should use to interact iphone a开发者_如何学JAVApp with server?
  3. If there is no particular kind of server then what kind of server can be used?
  4. What are their advantages and disadvantages?
  5. What should the iPhone app (which is the client) do in order to interact with the server?
  6. How does the server know which iPhone to send data to?
  7. What should the server do in order to interact with iPhone app (client)?


Your best bet is to have your iPhone make web requests of a web server. Your iPhone app acts just like a web browser, making http requests to a web server, and parsing the response.

I'm building an app right now that hits PHP scripts I've written that do database work, etc, and return JSON objects. It's not fancy--I could have built a whole SOAP or RPC web service, but I didn't do that, it just makes GET requests with query-string arguments.

There are handy libraries you want to know about. Google "iPhone JSON" to find the JSON library written by Stig Brautaset, that's the one most people seem to be using. Also, rather than putting yourself through all the hoops that the iPhone's built-in web client framework requires, go get ASIHTTPRequest, a very powerful and MUCH simplified web client library.

As a general rule, you want to do as much processing on the server as possible. For instance, there's a place in my app I'm searching for events happening within a user-specified range of their local coordinates ("within 10 miles of me"). I wrote PHP to build a latitude/longitude bounding box, and query from the database based on that. That's WAY faster than bringing a bunch of events down and then asking Core Location to calculate their distance from where I'm standing.


You've asked quite a few questions so I'll try my best to answer them all:

First, you need to be a bit clearer, what type of server are you talking about? Email server, web server, lolcat server, it depends.

At the basic level, the iphone communicates over the internet. The internet uses Internet Protocol, and there are two standard protocols built atop of IP: Transmission Control Protocol, and User Datagram Protocol. Each has it's own uses and functions.

TCP/IP and UDP/IP make up the backbone of internet communication.

A more specific application protocol is built atop of these two internet protocols, with a specific format to a given application. For example, HTTP is the standard protocol for transferring HTML and other Web information between a web server to a web browser client, over TCP.

So, your iPhone would use whatever protocol is required to commuincate with the server. For more common server communication, the iOS SDK provides methods to construct messages (for example if you wish to make an HTTP request to a web server, you can use initWithContentsOfURL to send a GET request).

If you built a custom server, then you will need construct the required message protocol on the iphone, and send it to the server, using either TCP or UDP (whatever your custom server expects).

0

精彩评论

暂无评论...
验证码 换一张
取 消