两个 Android 应用程序如何相互通信?
两个 Android 应用程序的一般通信架构是什么?
情况1:
我有两个android应用程序,
a)一个是等待客户端请求的服务器,处理请求(从某些sqlite数据库读取数据)并将结果返回给客户端。该服务器应用程序在其自己独立的 Android 手机上运行。
b) 第二个是向 (a) 中的服务器应用程序发送请求的客户端,它也运行在自己独立的 Android 手机上。
问题是,两个应用程序是否必须通过移动服务提供商才能进行通信?或者他们可以通过一些公共 IP/WIFI 等直接相互交谈。这个应用程序的通信结构/体系结构是什么?
案例 2:
我有一个在独立 Android 手机上运行的 Android 应用程序,我希望它与在互联网上某处机器上运行的某个服务器应用程序(Web 服务器/应用程序服务器)进行通信,发送请求并获取一些反馈。
还是那句话,两个应用程序是否必须通过移动服务提供商才能方便通信?或者他们只是通过某个公共 IP 建立直接的 TCP/IP 通信?
任何参考文章都会很有帮助。
谢谢加斯
What is the general communication architecture for two android applications?
Case 1:
I have two android applications,
a) One is a server that waits for client request, process the request( read data from some sqlite db) and return the results to the client. This server application runs on its own independent android phone.
b) The second is the client that sends the request to the server application in (a) and it too runs on its own independent android phone.
Question is, do the two applications have to go through the Mobile Service Provider to enable communication? or they can just talk to each other directly via some public IP/WIFi etc. What is the communication structure/architecture for this applications?
Case 2:
I have an android application running on an independent android phone, and i want it to talk to some server application (Web Server / Application Server) running in some machine somewhere on the internet, sends request and get some feed back.
Again, do the two applications have to go through the Mobile Service Provider to facilitate communication? or they just establish a straight TCP/IP communication via some public IP?
Any reference articles would really help.
Thanks
Gath
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果你想使用3G,可以。如果您想使用 WiFi,则不行。一般来说,Android应用程序并不关心互联网连接来自哪里。
如果他们有WiFi连接,他们就有WiFi连接。您如何使用 WiFi 连接取决于您,使用 Java 套接字,并考虑 Internet 访问的所有常见问题(例如 NAT)。
您请求一个 Java 套接字。您将获得一个 Java 套接字。您可以使用 Java 套接字执行某些操作。 Java 套接字从何而来以及它的连接如何工作通常是秘密的:3G、WiFi、一群非常小的旅鸽等。
If you want to use 3G, yes. If you want to use WiFi, no. Generally, Android applications do not care where the Internet connection comes from.
If they have a WiFi connection, they have a WiFi connection. What you do with that WiFi connection is up to you, using Java sockets, and respecting all the normal problems with Internet access (e.g., NATs).
You ask for a Java socket. You get a Java socket. You do something with the Java socket. Where that Java socket comes from and how its connection works is generally under the covers: 3G, WiFi, a squadron of very tiny passenger pigeons, etc.
我建议 Android – IPC、aidl 和 IBinder 和 掌握 Android 的 IPC 机制作为开始。之后就在 Google 上搜索“Android IPC”
I'd suggest Android – IPC, aidl and IBinder and Grasping Android's IPC mechanism for a start. After that just hunt on Google for 'Android IPC'
有关同步的内容请参见Android 中的同步
Something about sync is here Synchronization in Android