Android客户端服务器通信混乱
项目描述:我必须在android中制作一个应用程序,它从GPS获取纬度和经度,并将其位置和标识转发到服务器。在服务器端应该有一个网页,它不断接收来自 Android 应用程序的消息并在 Google 地图上显示位置。
假设有 10 个 Android 设备在不同的地方运行我们的应用程序。在服务器端,我们必须在 Google 地图上的设备位置处显示 10 个标记。
我所做的:我在android中制作了一个应用程序,它可以从GPS获取纬度和经度。我熟悉android上的socket编程。我已经在服务器端实现了网页,其中包含谷歌地图并显示标记。
困惑:
如何制作服务器?
如何将数据从 Android 传输到服务器以及服务器端需要什么应用程序来接收来自 Android 的数据。是否需要任何将自身绑定在服务器或网页的特定端口的桌面或控制台应用程序足以让我实现此目标。
我必须使用什么协议? 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:
How can I make a server?
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.
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
常见的设置可以是这样的:
具有以下内容:
这样,你就得到了你想要的。
另一方面,如果我们谈论客户端-服务器架构,客户端发送请求并获取响应。就是这样。为此,客户端访问服务器端脚本来获取这些响应。同样,您的 Android 应用程序访问特定的服务器端脚本并获取响应。就是这样。
如果您想要实现服务器发起的与 Android 的通信,则必须使用推送机制,例如 Cloud to Device Messaging (C2DM)
Cheers。
A common setting can be like this:
Have following things:
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.
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.