移动客户端/服务器应用程序的基于 Socket 与基于 HTTP 的通信

发布于 2024-10-22 23:13:23 字数 1162 浏览 0 评论 0原文

我最近决定承担一个相当大的软件工程项目,其中涉及开发基于客户端-服务器的应用程序。我的计划是开发尽可能多的客户端:包括原生 iPhone、Android 和 Blackberry 应用程序以及基于 Web 的应用程序。

对于我的服务器,我计划使用 VPS(可能来自 slicehost.com),运行带有 MySQL 数据库的 Linux 风格。我的第一个问题是客户端与服务器交互的策略应该是什么。我的想法是:

  1. 使用 PHP 脚本进行基于 HTTP-POST 或 GET 的通信。
    这是我非常熟悉的事情 - 将信息从表单传递到 PHP 脚本,使用它并返回输出。我假设我希望将输出作为某种基于 XML 或 JSON 的字符串返回给客户端。我还假设我想为想要与我的服务器交互的客户端创建一个定义良好的 API。

  2. 与 PHP 脚本、Java 程序或 C++ 程序进行基于套接字的通信
    这个我不太熟悉。我已经学习了有关创建脚本或简单应用程序的基本教程,这些脚本或简单应用程序创建套接字、侦听连接并返回数据。我假设此方法的通信数据开销比基于 HTTP 的方法少得多。我的梦想是有很多并发客户端在使用,所有客户端都与服务器/数据库一起工作。我不确定基于简单 HTTP/PHP 脚本的通信设计是否可以有效扩展以满足许多客户的需求。另外,我最终可能希望能够通过各种服务器事件触发客户端的服务器推送功能。我也不确定哪种编程语言最适合这个。如果效率是一个大问题,我想 PHP 脚本可能不够高效?

有没有一种普遍接受的方法来做到这一点?对我来说,这是弥补我目前的一些技能之间差距的尝试。我在 PHP 以及与 MySQl 数据库接口来提供动态网页方面拥有丰富的经验。我在开发本机 iPhone 应用程序方面也有很多经验(但是没有任何一个应用程序具有任何重要的基于服务器的通信)。我还使用过 Java/C++,并用这两种语言开发了与 MySQL 交互的应用程序。

我预计我的客户不会向服务器发送/接收大量数据。相当于每个给定客户端事件的一组字符串。

另一个问题:使用 VPS - 好主意吗?我显然不想支付完全专用的服务器费用(slicehost 提供的 VPS 起价约为 20 美元/月),并且我假设 VPS 将能够满足一些初始客户的要求。随着越来越多的用户开始与我的服务器交互,我假设可以迁移到越来越大的“切片”,并可能在必要时最终迁移到完全专用的服务器。

感谢您的建议! :)

I've recently decided to take on a pretty big software engineering project that will involve developing a client-server based application. My plan is to develop as many clients as possible: including native iPhone, Android and Blackberry Apps as well as a web-based app.

For my server I'm planning on using a VPS (possibly from slicehost.com) running a flavor of Linux with a MySQL database. My first question is what should be my strategy for clients to interface with the server. My ideas are:

  1. HTTP-POST or GET based communication with a PHP script.
    This is something I'm very familiar with - passing information to a PHP script from a form, working with it and returning output. I'm assuming I'd want to return output to clients as some sort of XML or JSON based string. I'm also assuming I'd want to create a well defined API for clients that want to interface with my server.

  2. Socket based communication with either a PHP script, Java program, or C++ program
    This I'm less familiar with. I've worked with basic tutorials on creating a script or simple application that creates a socket, listens for a connection and returns data. I'm assuming there is far less communication data-overhead with this method than an HTTP based method. My dream is for there to be A LOT of concurrent clients in use, all working with the server/database. I'm not sure if a simple HTTP/PHP script based communication design can scale effectively to meet the needs of many clients. Also, I may eventually want the capability of a Server-Push to clients triggered by various server events. I'm also unsure of what programming language is best suited for this. If efficiency is a big concern I'd imagine a PHP script might not be efficient enough?

Is there a commonly accepted way of doing this? For me this is an attempt to bridge a gap between some of my current skills. I have a lot of experience with PHP and interfacing with a MySQl database to serve dynamic web pages. I also have a lot of experience developing native iPhone applications (however none that have had any significant server-based communication). Also I've worked with Java/C++, and I've developed applications in both languages that have interfaced with MySQL.

I don't anticipate my clients sending/receiving a tremendous amount of data to/from a server. Something on par with a set of strings per a given client-side event.

Another question: Using a VPS - good idea? I obviously don't want to pay for a full-dedicated server (slicehost offers a VPS starting at ~ $20/month), and I'm assuming a VPS will be capable of meeting the requirements of a few initial clients. As more and more users begin to interface with my server, I'm assuming it will be possible to migrate to larger and larger 'slices' and possibly eventually moving to a full-dedicated server if necessary.

Thanks for the advice! :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

昇り龍 2024-10-29 23:13:23

我建议选择简单的 HTTP,至少在您的需求超出其功能之前是这样。 (您的应用程序需要的状态越多,适合的 HTTP 就越少)。

为了实现低成本和可扩展性,使用 Rackspace 或 Amazon 等云可能不会出错。但我才刚刚开始使用这些,到目前为止我的服务器一直是 tektonic 的 VPS。

I'd say go with the simplicity of HTTP, at least until your needs outgrow its capabilities. (The more stateful your application needs to be, the less HTTP fits).

For low cost and scalability, you probably can't go wrong with a cloud like Rackspace's or Amazon's. But I'm just getting started with those, my servers have been VPSs from tektonic until now.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文