当前位置: 动力学知识库 > 问答 > 编程问答 >

android - Best way to send messages between devices running the same application?

问题描述:

I am planning on creating an application that will allow multiple devices running the application to send messages (urls/ids/strings) to a another device running the application.

So if I had 4 devices. Device A, B, C & D. Device A decides to become the host device, devices B, C & D will then like to see Device A through the app, and then send some requests to Device A.

My challenge is picking the correct/most efficient and cost effective method of doing this.

I have considered the following options

  • Peer-to Peer connection
  • Starting and running a server on host device on the fly
  • Push notifications

I have deliberately avoided the user of a middle-man server as I want to avoid additional costs as I do not have any foresight on how this app will do commercially. I secondly must mention that at any one time, I would not expect more than 10 devices would want to send messages to this 'Host Device' and no more than 50-100 messages to be sent over the course of 5 hours. So not to taxing.

All the devices would be on their individual mobile networks but potentially on the same wifi. I do not want to restrict this to being on the same network.

Any thoughts on what would be the best option in my case would be greatly appreciated. I am personally leaning towards peer-to-peer as it would seem easiest to implement and would do fine with the number of requests the host device would be able to handle.

Thanks in advance,

James

网友答案:

Considering they may be on different mobile networks and you don't need real time communication, I would consider push notifications.

And you can have problems with peer-to-peer connection across different mobile networks, it is probably blocked. And you would waste resources to connect/disconnect for every message, because you can't keep the connection running or you will drain the device's battery.

分享给朋友:
您可能感兴趣的文章:
随机阅读: