简体   繁体   English

从Android设备向Apache Web服务器发送数据的有效方法

[英]Efficient way to send data from Android device to Apache web server

I want to send sensor data from an Android device to a Apache web server. 我想将传感器数据从Android设备发送到Apache Web服务器。 The sensor is connected to the Android device using the IOIO board and is sampled at an regular interval. 传感器使用IOIO板连接到Android设备,并定期进行采样。

The raw sensor data is approximately 1 byte/second and I'm trying to find an efficient way to send this to the web server which is based on Apache and has support for PHP and ASP (ChiliASP I think). 原始传感器数据大约为1字节/秒,我正在尝试找到一种有效的方法将其发送到基于Apache并支持PHP和ASP(我认为是ChiliASP)的Web服务器。

In order to have a low monthly cost, I would like to use pre-paid mobile subscription and these usually have a fixed maximum data limit (something like 500 MB/month). 为了降低每月费用,我想使用预付费移动订阅,这些订阅通常具有固定的最大数据限制(例如500 MB /月)。

Since the sensor should send data 24/7, I would like to keep the required data traffic at a minimum. 由于传感器应24/7全天候发送数据,因此我希望将所需的数据流量保持在最低水平。 Even if the amount of data is not very large, I think that the overhead in terms of protocol headers could be an issue. 即使数据量不是很大,我也认为协议头的开销可能是个问题。 If each sample (1 byte) is sent separately, the overhead/payload ratio will be very poor. 如果每个样本(1个字节)分别发送,则开销/有效负载比率将非常差。 On solution is of course to aggregate some data and send it in bigger chunks. 在解决方案上当然是聚合一些数据并以更大的块发送。

I have successfully tested Java HttpURLConnection to send data using an HTTP POST and have some questions about this: 我已经成功测试了Java HttpURLConnection以使用HTTP POST发送数据,并且对此有一些疑问:

  1. How large is the overhead due to HTTP headers? HTTP标头导致的开销有多少? Is there some easy way to measure it? 有一些简单的方法可以衡量它吗?
  2. Is there some other protocol supported by Android and Apache which I could consider? 我可以考虑考虑Android和Apache支持的其他协议吗?

You can use a simple HTTP GET/POST request and send json encoded data as parameters to a web service implemented in php or any other language of your choice. 您可以使用简单的HTTP GET / POST请求,并将json编码的数据作为参数发送到以php或您选择的任何其他语言实现的Web服务。 I don't think it get's simpler/smaller than http get/post and json (unless someone can correct me). 我认为它不会比http get / post和json更简单/更小(除非有人可以纠正我)。 JSON is an excellent, easy and flexible format for data interchange and is much simpler and more concise than xml. JSON是一种用于数据交换的出色,简单且灵活的格式,并且比xml更简单,更简洁。 JSON parsing is available natively in most languages including Java, JavaScript and PHP. JSON解析可用于大多数语言,包括Java,JavaScript和PHP。 It also very widely used. 它也被广泛使用。

An HTTP get request, for example, doesn't have much overhead except the length of parameters you wish to send. 例如,HTTP get请求除了您希望发送的参数长度外没有太多开销。 Here's a typical GET request: 这是一个典型的GET请求:

GET /pub/WWW/TheProject.php?arg1=foo&arg2=bar HTTP/1.1 

arg1 & arg2 are the arguments I'm passing to TheProject.php. arg1arg2是我传递给TheProject.php的参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM