0

I have a question regarding http requests and responses.

I know that I can send a request to a server from my device (I can build and send a GET request to http://google.com for example). But what if I am Google and I want to send a request from the server to the user's device? How do I do that?

I understand that when the server receives a request, it can answer it, but in this case I want the server to send the request to the user's device. Just like WhatsApp does when you receive a new message.

Thanks for the help!

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
  • 2
    So you are looking for push notifications? – takendarkk Jan 10 '22 at 19:29
  • 1
    Clients often are not also servers, so they don't accept _incoming requests_. Beyond that, you'd need an IP address, at the very least (since there is no `client-foo.bar.com`), and that IP is not reliable for mobile devices. – OneCricketeer Jan 10 '22 at 19:29
  • @takendarkk not exactly. I need to send data from the server to the user, but I think that putting a method on the user side that keeps asking for that info every 2 seconds is not very efficient. So I wanted to know if the server can send the info without a request from the user – rodovelazquez Jan 10 '22 at 19:35
  • Push notifications do not execute every 2 seconds on a client's device. Server just sends data to a given device token or id which is generated when the user installs an app. – takendarkk Jan 10 '22 at 20:06

1 Answers1

0

There are several options for sending information from the server to a client:

  1. Push notifications - depends on the platform you are using
  2. Constructing a Websocket connection that allows bi-directional communication I'm sure there are more options but those are the two that come up to my mind right away.

It really depends on your application use case. For example, a chat application would like to have a socket open between it and the server so it can update frequently on new messages, etc. On the other had some simple Calendar applications might want to use push notifications to send reminders on certain dates and times.

CloudBalancing
  • 1,461
  • 2
  • 11
  • 22