简体   繁体   English

从服务器如何在没有任何请求的情况下调用Android应用程序?

[英]From server how to call an Android app without any request?

In my app I have functionality like server-side some updates is done. 在我的应用程序中,我具有服务器端之类的功能,一些更新已完成。 When every updates is happen in server-side I need send those data to app without using push notifications. 当服务器端发生每次更新时,我需要不使用推送通知就将这些数据发送到应用程序。

Take example of Ola Cabs. 以Ola出租车为例。 Whenever user open the app it will show all cabs information nearby user. 每当用户打开应用程序时,它将在用户附近显示所有出租车信息。 At the same time it will send data to the cab drivers telling that a customer needs cab like that. 同时,它将向出租车司机发送数据,告知客户需要这样的出租车。 How to implement this functionality with out push notifications? 如何在没有推送通知的情况下实现此功能?

By using this things we can do that 通过使用这些东西,我们可以做到

1) push notifications 1)推送通知

2) explicitly calling the server from client with given time (its bad process) 2)在给定的时间从客户端显式调用服务器(其错误的过程)

Is there any solution other than these things? 除了这些事情,还有其他解决方案吗?

How could client get response without request? 客户如何在没有请求的情况下得到回应? Please read OSI Model and TCP/IP protocol . 请阅读OSI模型TCP / IP协议 Because server cannot send response without request. 因为服务器无法在没有请求的情况下发送响应。 So client have to initialize request first and wait for response from server. 因此,客户端必须先初始化请求,然后等待服务器的响应。 If you want to do same thing without GCM then i will suggest you to use socket programming. 如果您想在没有GCM的情况下做同样的事情,那么我建议您使用套接字编程。 In that you can be open client port continuously to receive messages (response) without any request initiated by client. 这样,您可以连续打开客户端端口以接收消息(响应),而无需客户端发起任何请求。

But again, continuously opening socket port, drains device batteries, and this is bad process. 但是同样,持续打开插座端口会耗尽设备电池的电量,这是一个不好的过程。 In case of GCM it only open port for while when client send request to server and close after response. 如果是GCM,则仅在客户端向服务器发送请求时打开端口,然后在响应后关闭。 So I suggest you to use GCM but still you have problem with GCM then use socket programming like chat applications (eg WhatsApp) 因此,我建议您使用GCM,但仍然遇到GCM问题,然后使用聊天程序之类的套接字编程(例如WhatsApp)

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

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