用于移动客户端/服务器应用程序的基于Socket vs HTTP的通信 [英] Socket vs HTTP based communication for a mobile client/server application

查看:132
本文介绍了用于移动客户端/服务器应用程序的基于Socket vs HTTP的通信的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近决定采取一个相当大的软件工程项目,涉及开发基于客户端 - 服务器的应用程序。我的计划是开发尽可能多的客户端:包括原生iPhone,Android和黑莓应用程序以及一个基于网络的应用程序。

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.

对于我的服务器,我计划使用VPS(可能从slicehost.com)运行一个Linux的味道与MySQL数据库。我的第一个问题是什么应该是我的策略客户端与服务器接口。我的想法是:

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. 使用PHP脚本进行HTTP-POST或GET通讯。

    这是我非常熟悉的 - 将信息从表单传递到PHP脚本,使用它并返回输出。我假设我想要返回输出到客户端作为某种基于XML或JSON的字符串。

  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.

基于套接字的通信与基于套接字的通信PHP脚本,Java程序或C ++程序

这我不太熟悉。我已经完成了有关创建脚本或简单应用程序的基本教程,创建一个套接字,侦听连接并返回数据。我假设有更少的通信数据开销与这种方法比基于HTTP的方法。我的梦想是有大量的并发客户端在使用,所有工作与服务器/数据库。我不确定一个简单的基于HTTP / PHP脚本的通信设计能否有效地扩展以满足许多客户的需求。此外,我最终可能希望服务器推送到由各种服务器事件触发的客户端的能力。我也不确定什么编程语言是最适合这个。如果效率是一个很大的问题,我想象一个PHP脚本可能不够高效。

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?

接受的方式这样做?对我来说,这是一个尝试,以弥合我目前的一些技能之间的差距。我有很多PHP的经验和与MySQl数据库连接以提供动态网页。我也有很多开发本机iPhone应用程序的经验(但没有一个有过任何重要的基于服务器的通信)。我已经使用Java / C ++,并且已经开发了与MySQL接口的两种语言的应用程序。

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.

另一个问题:使用VPS是个好主意吗?我显然不想支付一个全面的专用服务器(slicehost提供VPS从〜$ 20 /月开始),我假设一个VPS将能够满足几个初始客户的要求。随着越来越多的用户开始与我的服务器接口,我假设有可能迁移到更大和更大的切片,并且如果必要,最终可能迁移到一个完全专用的服务器。

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.

感谢您的建议! :)

推荐答案

我会说HTTP的简单性,至少直到你的需求超出它的能力。 (你的应用程序需要的状态越多,HTTP的适合性越低)。

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

对于低成本和可扩展性,你可能不会错过一个像Rackspace的云或亚马逊的。但我只是开始与那些,我的服务器已经是从tektonic到现在的VPSs。

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.

这篇关于用于移动客户端/服务器应用程序的基于Socket vs HTTP的通信的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆