-1

Actually I need to send data from Angular to an android device. Requirement is to send data to the android device which is accepting through android input/output stream methods.

Please help me and correct me if you are not getting what I am saying. How can I send data from angular to an android device knowing its ip and port.

Update

I have updated my title, I hope it is clear now

WasiF
  • 26,101
  • 16
  • 120
  • 128
  • If you have a destination socket (ip:port), then my best guess is to use the default way your team uses to send over tcp/ip or http. (https://angular.io/guide/http). If you are totally confused, then please ask your "senior" for advice. We do not have insight into your companies best practices – Marco Dec 21 '18 at 08:04
  • Possible duplicate of [Console input in TypeScript](https://stackoverflow.com/questions/33858763/console-input-in-typescript) – Kannan Thangadurai Dec 21 '18 at 08:06
  • I assume your Angular app sends data from the browser to a backend API, that then routes that data to a GCM that your Android app gets push notifications from? Is that correct? – AnonymousSB Dec 21 '18 at 08:35

1 Answers1

1

In a browser there is no stdin, also known as a console. The input would most likely be from user input on the page in the form of an input field.

Most likely your structure is setup as follows:

Angular (browser) > API (server) > GCM (push) > Android Device

Here's an example of how you can take input from a user and send it to a backend api, the GCM portion is most likely already configured for your teams project.

const theForm = document.forms.theForm;

theForm.addEventListener('submit', (event) => {
  event.preventDefault();
  
  const data = new FormData(theForm);
  data.append('movies', ["I Love You Man", "Role Models"]);
  
  fetch(
    'https://reqres.in/api/users',
    {
      method: 'POST',
      body: JSON.stringify(data),
    })
    .then(resp => resp.json())
    .then(data => console.log(data));
});
<form name="theForm">
  <input type="text" name="name" placeholder="name" />
  <button type="submit">Submit</button>
</form>
AnonymousSB
  • 3,516
  • 10
  • 28
  • @WasiF I mentioned NodeJS because your question isn't very clear. You mention an "android backend", but that isn't a thing, so I thought perhaps your terminology was slightly off. – AnonymousSB Dec 21 '18 at 08:31