【问题标题】:What is equivalent of android input/output stream in typescript/javascript什么相当于打字稿/javascript中的android输入/输出流
【发布时间】:2018-12-21 08:01:19
【问题描述】:

实际上我需要将数据从Angular 发送到安卓设备。要求是通过androidinput/output stream方法将数据发送到正在接受的android设备。

如果您没有理解我的意思,请帮助我并纠正我。如何将数据从 Angular 发送到知道其 ipport 的 android 设备。

更新

我已经更新了我的标题,希望现在清楚了

【问题讨论】:

  • 如果您有一个目标套接字 (ip:port),那么我最好的猜测是使用您的团队使用的默认方式通过 tcp/ip 或 http 发送。 (angular.io/guide/http)。如果您完全感到困惑,请向您的“前辈”寻求建议。我们无法深入了解贵公司的最佳做法
  • 我假设您的 Angular 应用程序将数据从浏览器发送到后端 API,然后将该数据路由到您的 Android 应用程序从中获取推送通知的 GCM?对吗?

标签: javascript typescript inputstream outputstream


【解决方案1】:

在浏览器中没有stdin,也称为控制台。输入很可能来自用户在页面上以输入字段的形式输入。

您的结构很可能设置如下:

Angular(浏览器)> API(服务器)> GCM(推送)> Android 设备

这是一个示例,说明如何从用户那里获取输入并将其发送到后端 api,GCM 部分很可能已经为您的团队项目配置。

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>

【讨论】:

  • @WasiF 我提到了 NodeJS,因为你的问题不是很清楚。您提到了“android 后端”,但这不是一回事,所以我认为您的术语可能略有偏差。
猜你喜欢
  • 1970-01-01
  • 2019-09-28
  • 1970-01-01
  • 1970-01-01
  • 2022-08-12
  • 2019-01-25
  • 2022-08-05
  • 2014-09-14
  • 2018-09-05
相关资源
最近更新 更多