简体   繁体   English

将Node与Phonegap应用集成

[英]Integrate Node with Phonegap app

I want to develop an hybrid cross platform app that creates a socket connection to given Ip. 我想开发一个混合的跨平台应用程序,该应用程序创建到给定IP的套接字连接。 I have achieved it using webTCP module in node.js by running node from cmd to start the server. 我已经通过在cmd中运行node来启动服务器,并在node.js中使用webTCP模块实现了它。 Now I want to pack this in to an app using Phonegap. 现在,我想使用Phonegap将其打包到应用程序中。 But my question is how do I run node(to start server) in mobile through the app created using phonegap. 但是我的问题是如何通过使用phonegap创建的应用程序在移动设备中运行节点(以启动服务器)。 Do we need to install node in mobile. 我们是否需要在移动设备上安装节点。 If so how can I do that? 如果可以,我该怎么办? Thanx in advance. 提前感谢。

nodejs isn't done (yet) to run on Android. 尚未完成nodejs以便在Android上运行。 NodeJs is a server thing so it should run on your server to run tour backend. NodeJs是服务器,因此应在您的服务器上运行以运行巡回后端。

In order to do what you want to do you will have to redesign your architecture. 为了做您想做的事,您将不得不重新设计您的架构。

Indeed, Cordova/PhoneGap is a little server (actually it's is a WebView but you can approximate it to a static content delevery server). 确实,Cordova / PhoneGap只是一个小服务器(实际上,它是一个WebView,但是您可以将其近似于静态内容缺失的服务器)。 So you will have to made your cordova app talk to your node-server. 因此,您将必须使cordova应用程序与节点服务器对话。

1. CORS 1. CORS

Cordova-app <- INTERNET -> Node-server

The first thing to do is to enable CORS, for nodejs and whitelist the adress of your node-server in cordova 首先要做的是为nodejs启用CORS,并在cordova中将节点服务器的地址列入白名单。

2. let's talk 2.让我们谈谈

Now you can start talking to your server with your cordova app, there is many ways to do that : 现在,您可以开始使用Cordova应用程序与服务器进行对话了,有很多方法可以做到这一点:

3. being more powerful 3.更强大

You will need more powerful feature between your app and your server side. 您将需要在应用程序和服务器端之间提供更强大的功能。 In order to do that, you could need some WebApp framework. 为此,您可能需要一些WebApp框架。 Indeed, they automate for you the connection between the server and your application and offer you a cool and easy environment to do great apps. 实际上,它们为您自动实现了服务器与应用程序之间的连接,并为您提供了一个酷而轻松的环境来制作出色的应用程序。 If you want to know more about it, you could look at 如果您想进一步了解它,可以看看

  • BackBone 骨干
  • Marionette 木偶
  • AngularJs AngularJs

Hope that help. 希望对您有所帮助。

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

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