Android客户端服务器通信混乱

发布于 2024-10-20 05:03:33 字数 672 浏览 2 评论 0原文

项目描述:我必须在android中制作一个应用程序,它从GPS获取纬度和经度,并将其位置和标识转发到服务器。在服务器端应该有一个网页,它不断接收来自 Android 应用程序的消息并在 Google 地图上显示位置。

假设有 10 个 Android 设备在不同的地方运行我们的应用程序。在服务器端,我们必须在 Google 地图上的设备位置处显示 10 个标记。

我所做的:我在android中制作了一个应用程序,它可以从GPS获取纬度和经度。我熟悉android上的socket编程。我已经在服务器端实现了网页,其中包含谷歌地图并显示标记。

困惑:

  1. 如何制作服务器?

  2. 如何将数据从 Android 传输到服务器以及服务器端需要什么应用程序来接收来自 Android 的数据。是否需要任何将自身绑定在服务器或网页的特定端口的桌面或控制台应用程序足以让我实现此目标。

  3. 我必须使用什么协议? UDP、TCP/IP,还是直接使用 HTTP 或 HTTPS 流?

我只需要一些关于我的问题的指导,因为我从未从事过 Android 和客户端服务器通信工作。如果您认为这个问题含糊不清,那么请推荐一本有关网络的书或任何您认为适合此类问题的书。

Project Description: I have to make an application in android which gets the Latitude and Longitude from GPS and forward their location with identification to server. On the server end there should be web page which continuously receives the messages from the Android application and shows the location on Google maps.

Suppose there are 10 Android devices at different places in which our application is running. On the Server end we have to show 10 markers on Google maps at the location of devices.

What I have Done: I have made an application in android which gets Lat and Long from GPS. I'm familiar with socket programming on android. I've implemented the web page on the server end which has Google maps and shows the markers.

Confusion:

  1. How can I make a server?

  2. How can I transfer data from Android to server and what application required at server end which receive the data from Android. Is any desktop or console application needed which bind it-self at particular port of server, or web page is enough for me to achieve this target.

  3. What protocol do I have to use? UDP, TCP/IP, or use the HTTP or HTTPS steam directly?

I just need some direction about my problem because I have never worked in Android and Client Server Communication. If you think this question is vague then please recommend a book about networking or any which you think is suitable for this type of problem.

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

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

发布评论

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

评论(2

分开我的手 2024-10-27 05:03:33

常见的设置可以是这样的:

具有以下内容:

  • 服务器端的文件(PHP),其唯一目的是将从 android 设备接收到的数据(lat,lng)注入到 MySql 数据库
  • 服务器端的文件(PHP)其唯一目的是从 MySql 数据库中获取数据 (lat,lng)。该文件应该接收一个时间戳作为其参数,并返回在该时间戳之后保存的所有 lat、lng 值(为此,您的数据库必须存储时间戳)
  • 一个仅处理地图事物的文件(HTML + JS),具有实现的 AJAX 调用定期使用时间戳值轮询第二个文件以获取新的 lat、lng 值。当它获取值时,它会将它们绘制在地图上
  • 在 Android 设备上,让您的应用程序以特定的时间间隔不断将其位置发送到第一个 PHP 文件。

这样,你就得到了你想要的。

另一方面,如果我们谈论客户端-服务器架构,客户端发送请求并获取响应。就是这样。为此,客户端访问服务器端脚本来获取这些响应。同样,您的 Android 应用程序访问特定的服务器端脚本并获取响应。就是这样。

如果您想要实现服务器发起的与 Android 的通信,则必须使用推送机制,例如 Cloud to Device Messaging (C2DM)

Cheers。

A common setting can be like this:

Have following things:

  • A file (PHP) at server's end, whose sole purpose is to inject the data (lat,lng) received from android devices into a MySql database
  • A file (PHP) at server's end whose sole purpose is to fetch you the data (lat,lng) from the MySql databse. This file should receive a timestamp as its argument and return all the values of lat,lng who have been saved after that timestamp (For this, your database must store timestamp)
  • A file (HTML+JS) which just handles the map thing, has an AJAX call implemented which polls the second file at regular intervals with a timestamp value to get new lat,lng values. and when it gets the values, it plots them on the map
  • On the Android devices, make your app in a way that it keeps sending its location to the first PHP file at a particular time interval.

This way, you get what you wanted.

On the other note, If we talk about client-server architecture, a client sends the request and gets the response. that's it. for this, client accesses a server side script to get those responses. same way, your android app accesses a particular server side script and gets the response. That's it.

In the case when you want to implement server initiated communication to android, you'll have to use push mechanism, like Cloud to Device Messaging (C2DM)

Cheers.

ζ澈沫 2024-10-27 05:03:33

Afaik...

首先,您需要使用 Android SDK 中提供的位置基础服务来获取 GPS 数据(请参阅位置管理器、位置侦听器等...)

困惑:- 困惑在于

我如何制作服务器。

答:无法帮助您解决此问题,因为我不擅长配置服务器

如何将数据从 Android 传输到服务器以及从 Android 接收数据的服务器端需要什么应用程序。是否需要任何将自身绑定在服务器或网页的特定端口的桌面或控制台应用程序足以让我实现此目标。

答:您可以使用 Web 服务传输由纬度和经度组成的数据,该服务使用 get 或 post 方法接收数据,然后每次在位置侦听器上调用 OnLocationChanged 方法时将其转储到数据库中。最好你可以在你的服务器中配置一个mysql数据库,然后用它来存储数据。您需要设计的网页能够经常从数据库中获取与位置相关的数据,然后相应地显示标记。

我必须使用什么协议 UDP 或 TCP/IP,还是直接使用 HTTP 或 HTTPS 流?

Ans:如果您了解 php,那么您可以使用 REST 服务,或者如果您是 .Net 类型的人,您可以使用 SOAP Web 服务,该服务使用简单的 http post 方法将数据更新到服务器。

希望这有帮助。

Afaik...

First you need to get the data of GPS by using Location baser services provided in Android SDK(See Location MAnager, Location Listener etc etc...)

Confusion:- The confusion is that

How can I make a server.

Ans: Cant help you with this because i m not expert at configuring servers

How to transfer data from Android to server and what application required at server end which receive the data from Android. Is any desktop or console application needed which bind it-self at particular port of server, or web page is enough for me to achieve this target.

Ans: You can transfer the data that consists of the Latitude and Longitude using a webservice that recieves the data using get or post methods and then dumps it into your database every time the OnLocationChanged method is called on Location Listener. Preferably u can configure a mysql database in your server and then use it for your data storage. The web page you need to design in such a way that it frequently gets the location related data from the database and then display markers accordingly.

What protocol which I have to use UDP or TCP/IP, or use directly the HTTP or HTTPS steam?

Ans: If you are aware of php then u can use REST services or if you are .Net kind of guy you can use a SOAP webservice that uses simple http post methods to update data to the server.

Hope this helps.

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