iphone应用程序如何与服务器交互?

时间:2023-01-12 20:15:45

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

我是一名新的程序员,他是iPhone开发和服务器的新手。我有很多问题要问。

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

你不必回答所有问题;任何帮助表示赞赏!

  1. How does iPhone apps interact with server?
  2. iPhone应用程序如何与服务器交互?
  3. Is there a particular kind of server i should use to interact iphone app with server?
  4. 是否有一种特殊的服务器我应该用来与服务器交互iphone应用程序?
  5. If there is no particular kind of server then what kind of server can be used?
  6. 如果没有特定类型的服务器,那么可以使用哪种服务器?
  7. What are their advantages and disadvantages?
  8. 它们的优点和缺点是什么?
  9. What should the iPhone app (which is the client) do in order to interact with the server?
  10. iPhone应用程序(客户端)应该做什么才能与服务器进行交互?
  11. How does the server know which iPhone to send data to?
  12. 服务器如何知道将数据发送到哪个iPhone?
  13. What should the server do in order to interact with iPhone app (client)?
  14. 服务器应该怎么做才能与iPhone应用程序(客户端)进行交互?

2 个解决方案

#1


12  

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.

您最好的办法是让您的iPhone发出Web服务器的Web请求。您的iPhone应用程序就像一个Web浏览器,向Web服务器发出http请求,并解析响应。

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.

我正在构建一个应用程序,它可以访问我编写的用于执行数据库工作等的PHP脚本,并返回JSON对象。这不是花哨 - 我可以构建一个完整的SOAP或RPC Web服务,但我没有这样做,它只是使用查询字符串参数发出GET请求。

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.

有你想知道的方便的图书馆。谷歌“iPhone JSON”找到Stig Brautaset编写的JSON库,这是大多数人似乎使用的。此外,不要让自己完成iPhone内置的Web客户端框架所需的所有环节,而是获得ASIHTTPRequest,这是一个非常强大且简化的简化Web客户端库。

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.

作为一般规则,您希望尽可能多地在服务器上进行处理。例如,我的应用程序中有一个位置我正在搜索在用户指定的本地坐标范围内发生的事件(“距离我10英里内”)。我编写了PHP来构建纬度/经度边界框,并根据该数据库从数据库中进行查询。这比将一堆事件放下来然后让Core Location计算他们离我站立的距离要快得多。

#2


4  

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.

首先,您需要更清楚一点,您在谈论什么类型的服务器?电子邮件服务器,Web服务器,lolcat服务器,这取决于。

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.

在基本层面,iphone通过互联网进行通信。互联网使用互联网协议,IP上有两个标准协议:传输控制协议和用户数据报协议。每个都有它自己的用途和功能。

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

TCP / IP和UDP / IP构成了互联网通信的支柱。

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.

在这两个互联网协议的基础上构建了更具体的应用协议,具有给定应用的特定格式。例如,HTTP是用于通过TCP在Web服务器与Web浏览器客户端之间传输HTML和其他Web信息的标准协议。

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).

因此,您的iPhone将使用与服务器通信所需的任何协议。对于更常见的服务器通信,iOS SDK提供了构造消息的方法(例如,如果您希望向Web服务器发出HTTP请求,则可以使用initWithContentsOfURL发送GET请求)。

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).

如果您构建了自定义服务器,则需要在iphone上构建所需的消息协议,并使用TCP或UDP(无论您的自定义服务器需要什么)将其发送到服务器。

#1


12  

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.

您最好的办法是让您的iPhone发出Web服务器的Web请求。您的iPhone应用程序就像一个Web浏览器,向Web服务器发出http请求,并解析响应。

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.

我正在构建一个应用程序,它可以访问我编写的用于执行数据库工作等的PHP脚本,并返回JSON对象。这不是花哨 - 我可以构建一个完整的SOAP或RPC Web服务,但我没有这样做,它只是使用查询字符串参数发出GET请求。

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.

有你想知道的方便的图书馆。谷歌“iPhone JSON”找到Stig Brautaset编写的JSON库,这是大多数人似乎使用的。此外,不要让自己完成iPhone内置的Web客户端框架所需的所有环节,而是获得ASIHTTPRequest,这是一个非常强大且简化的简化Web客户端库。

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.

作为一般规则,您希望尽可能多地在服务器上进行处理。例如,我的应用程序中有一个位置我正在搜索在用户指定的本地坐标范围内发生的事件(“距离我10英里内”)。我编写了PHP来构建纬度/经度边界框,并根据该数据库从数据库中进行查询。这比将一堆事件放下来然后让Core Location计算他们离我站立的距离要快得多。

#2


4  

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.

首先,您需要更清楚一点,您在谈论什么类型的服务器?电子邮件服务器,Web服务器,lolcat服务器,这取决于。

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.

在基本层面,iphone通过互联网进行通信。互联网使用互联网协议,IP上有两个标准协议:传输控制协议和用户数据报协议。每个都有它自己的用途和功能。

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

TCP / IP和UDP / IP构成了互联网通信的支柱。

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.

在这两个互联网协议的基础上构建了更具体的应用协议,具有给定应用的特定格式。例如,HTTP是用于通过TCP在Web服务器与Web浏览器客户端之间传输HTML和其他Web信息的标准协议。

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).

因此,您的iPhone将使用与服务器通信所需的任何协议。对于更常见的服务器通信,iOS SDK提供了构造消息的方法(例如,如果您希望向Web服务器发出HTTP请求,则可以使用initWithContentsOfURL发送GET请求)。

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).

如果您构建了自定义服务器,则需要在iphone上构建所需的消息协议,并使用TCP或UDP(无论您的自定义服务器需要什么)将其发送到服务器。