简体   繁体   English

连接两部Android手机,通过WIFI在他们之间传输数据

[英]Connecting two Android phones to transfer data between them over WIFI

Actually i am developing tracking app and want to send Location updates between two Android phones so that both can track one another over the Map. 实际上我正在开发跟踪应用程序,并希望在两个Android手机之间发送位置更新,以便两者可以通过地图跟踪彼此。 My application must get real time updates from other android device for better tracking. 我的应用程序必须从其他Android设备获得实时更新,以便更好地跟踪。
I Have searched couple of techniques but don't know which one is best 我搜索了几种技术,但不知道哪种技术最好

Using Sockets: making one device as Server while other as Client 使用套接字:将一个设备作为服务器而将其他设备作为客户端
Possible Limitation: 可能的限制:

  • What if IP address of Server is changed (because WIFI don't have a static IP) 如果更改了服务器的IP地址怎么办(因为WIFI没有静态IP)
  • Cannot access if the IP address of server is private 如果服务器的IP地址是私有的,则无法访问
  • Only client can connect to Server and Server cannot connect to Client 只有客户端可以连接到Server,Server无法连接到Client

Using Intermediate Server: create an intermediate server and make a communication via that server. 使用中间服务器:创建中间服务器并通过该服务器进行通信。
Possible Limitation: 可能的限制:

  • Slow because each Android device first send these updates to server and then server push these updates to other android device 慢,因为每个Android设备首先将这些更新发送到服务器,然后服务器将这些更新推送到其他Android设备

Please provide me your suggestion about which one is the best way to do this. 请告诉我你的建议,哪一个是最好的方法。

Since you didn't state the Device API level you want to support I'll provide you with an option for Android v4 (API level 14) devices. 由于您未说明要支持的设备API级别,因此我将为您提供Android v4(API级别14)设备的选项。 It's called Wi-Fi Direct and allows p2p connections between phones. 它被称为Wi-Fi Direct ,允许手机之间的p2p连接。 It's essentially your socket approach, but allows easy neighbour discovery and allows transfers in both directions. 它本质上是您的套接字方法,但允许轻松的邻居发现并允许双向传输。

Well wifi is out.. Not for your stated purpose at least. 好的wifi出来..至少不是为了你的既定目的。 Unless your map is quite small. 除非你的地图很小。 Wifi is for say 100 meters (on a really good day) 比如说100米(在非常好的一天)Wifi

Not knowing as much about android as I do of other mobiles, I'd say you're in for some pain. 不像我对其他手机那样了解Android,我会说你有些痛苦。 I'd suspect connecting to your phone with a peer to peer might be a real slog.. some providers won't let it happen. 我怀疑与点对点连接到你的手机可能是一个真正的困境......一些提供商不会让它发生。

I have an approach more than an answer.. 我的方法不仅仅是答案..
From an android phone, see if you can get your ip address. 从Android手机,看看你是否可以获得你的IP地址。
From a desk, ping that ip address. 从桌子上ping那个ip地址。
If it works, you're well on your way.. 如果它有效,你就可以了。
Id even say given the size of your info, you could use pinging as your main data carrier. 我甚至说,鉴于您的信息大小,您可以使用ping作为您的主要数据载体。
Pings can contain more than just random bytes. Ping可以包含的不仅仅是随机字节。 You could include an ID, and GPS in the contents you send in your ping. 您可以在ping中发送的内容中包含ID和GPS。
--- perhaps include a check sum --- ---也许包括一张支票---

Do most of the work desk to phone, because development would be faster.. Then when your phone is capable of catching the pings.. Well then sending the ping should be easy as. 大多数工作台都要打电话,因为开发会更快..然后当你的手机能够捕捉到ping ..那么发送ping应该很容易。

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

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