两个android应用程序如何相互通信?

时间:2021-10-25 14:05:12

What is the general communication architecture for two android applications?

两个Android应用程序的通用通信架构是什么?

Case 1:

情况1:

I have two android applications,

我有两个Android应用程序,

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.

a)一个是等待客户端请求的服务器,处理请求(从一些sqlite db读取数据)并将结果返回给客户端。此服务器应用程序在其自己的独立Android手机上运行。

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.

b)第二个是将请求发送到(a)中的服务器应用程序的客户端,它也运行在自己独立的Android手机上。

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?

问题是,两个应用程序是否必须通过移动服务提供商进行通信?或者他们可以通过一些公共IP / WIFi直接相互通信等。这些应用程序的通信结构/架构是什么?

Case 2:

案例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.

我有一个Android应用程序在一个独立的Android手机上运行,​​我希望它与某些服务器应用程序(Web服务器/应用程序服务器)在互联网上的某个机器上运行,发送请求并获得一些反馈。

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?

同样,这两个应用程序是否必须通过移动服务提供商来促进通信?或者他们只是通过一些公共IP建立直接的TCP / IP通信?

Any reference articles would really help.

任何参考文章都会有所帮助。

Thanks

谢谢

Gath

迦特

3 个解决方案

#1


3  

Question is, do the two applications have to go through the Mobile Service Provider to enable communication?

问题是,两个应用程序是否必须通过移动服务提供商进行通信?

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.

如果你想使用3G,是的。如果你想使用WiFi,没有。通常,Android应用程序不关心Internet连接的来源。

or they can just talk to each other directly via some public IP/WIFi etc.

或者他们可以通过一些公共IP / WIFi等直接互相交谈。

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).

如果他们有WiFi连接,他们有一个WiFi连接。您使用Java套接字来解决使用该WiFi连接的问题,并尊重Internet访问的所有常见问题(例如,NAT)。

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?

同样,这两个应用程序是否必须通过移动服务提供商来促进通信?或者他们只是通过一些公共IP建立直接的TCP / IP通信?

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.

你要求一个Java套接字。你得到一个Java套接字。您使用Java套接字执行某些操作。那个Java套接字的来源以及它的连接如何工作通常都在幕后:3G,WiFi,一个非常小的客座中队等。

#2


1  

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-IPC,aidl和IBinder以及掌握Android的IPC机制。之后只是在Google上搜索“Android IPC”

#3


0  

Something about sync is here Synchronization in Android

关于同步的东西在这里是Android中的同步

#1


3  

Question is, do the two applications have to go through the Mobile Service Provider to enable communication?

问题是,两个应用程序是否必须通过移动服务提供商进行通信?

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.

如果你想使用3G,是的。如果你想使用WiFi,没有。通常,Android应用程序不关心Internet连接的来源。

or they can just talk to each other directly via some public IP/WIFi etc.

或者他们可以通过一些公共IP / WIFi等直接互相交谈。

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).

如果他们有WiFi连接,他们有一个WiFi连接。您使用Java套接字来解决使用该WiFi连接的问题,并尊重Internet访问的所有常见问题(例如,NAT)。

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?

同样,这两个应用程序是否必须通过移动服务提供商来促进通信?或者他们只是通过一些公共IP建立直接的TCP / IP通信?

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.

你要求一个Java套接字。你得到一个Java套接字。您使用Java套接字执行某些操作。那个Java套接字的来源以及它的连接如何工作通常都在幕后:3G,WiFi,一个非常小的客座中队等。

#2


1  

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-IPC,aidl和IBinder以及掌握Android的IPC机制。之后只是在Google上搜索“Android IPC”

#3


0  

Something about sync is here Synchronization in Android

关于同步的东西在这里是Android中的同步