简体   繁体   English

将Android设备与Java服务器连接

[英]connecting an android device with a java server

I have to create an application in Android the gets from the GPS some data that needs to be stored in a DB at a Java server. 我必须在Android创建一个应用程序,该应用程序需要从GPS获取一些需要存储在Java服务器上的DB中的数据。

The problem I'm facing is that I don't know what protocol to use for connecting these devices. 我面临的问题是我不知道用于连接这些设备的协议。 Some say that I should use TCP/IP .Has anyone any clue why is this better than any other protocol? 有人说我应该使用TCP/IP 。有谁知道为什么它比其他协议更好? like http for example or any web service ? 例如http或任何web service

What I need to send between these 2 devices is some objects of this type: 我需要在这两个设备之间发送的是这种类型的一些objects

class Date{

String s1;
String s2;
Float f1;
int i1;

}

So, I'm sending on the remote side objects of this type: d1=new Date(); 因此,我正在发送这种类型的远程对象: d1=new Date(); continously. 连续地。 I mean that the data comes from a moving object....which moves about 8 hours a day...So during those 8 hours at intervals of 5-10 minutes I'm sending data! 我的意思是数据来自一个移动的对象……每天大约移动8个小时……所以在这8个小时中,我以5-10分钟的间隔发送数据!

Which is better and why?:D Thank u! 哪个更好,为什么?:D谢谢!

Which is better and why? 哪个更好?为什么?

That's still a bit of a subjective question as there could still be a number of ways to do this. 这仍然是一个主观的问题,因为仍有许多方法可以做到这一点。

In light of your edited question with the data which needs to be sent and the frequency (5-10 minutes), I'd suggest you look at implementing a simple HTTP service (listener) for the server end and simply pass the data using JSON. 根据您所编辑的问题以及需要发送的数据和频率(5-10分钟),我建议您考虑为服务器端实现一个简单的HTTP服务(侦听器),并简单地使用JSON传递数据。

Coding for both of the above is relatively simple. 以上两种情况的编码都比较简单。

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

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