Step by step _ node. js

Source: Internet
Author: User
Tags nets
This article describes how to build a nodejs server on an iPhone. This article provides detailed operation steps and commands. For more information, see 1. compile jxcore for running on ios

The code is as follows:

$ Mkdir ~ /Jxcore
$ Cd ~ /Jxcore
$ Git clone

The code is as follows:

$ Cd ~ /Jxcore

If the module not found of import which occurs, use the following statement to install which of python.

The code is as follows:

Sudo easy_install tools/which-1.1.0-py2.7.egg

If other problems occur, refer to the prerequisites for compiling ios with jxcore and take corresponding measures.

The code is as follows:

* GCC 4.2 or newer (for SpiderMonkey builds 4.7 +)
* Python 2.6 or 2.7
* GNU Make 3.81 or newer
* Libexecinfo (FreeBSD and OpenBSD only)
* For SpiderMonkey: 'Which 'python module (sudo easy_install tools/which-1.1.0-py2.7.egg)

2. install jxcore on mac

The code is as follows:

$ Sudo make install

3. create the cordova program. if cordova is not installed, install it on your own.

The code is as follows:

$ Cordova create hello com. example. hello HelloWorld
$ Cd hello

4. download and install the jxcore-cordova Plugin

The code is as follows:

$ Git clone

Use the template index.html of jxcore-cordovato

The code is as follows:

$ Cp./jxcore-cordova/sample/www/index.html./www/

Copy the jxcore package compiled in step 1 for ios

The code is as follows:

$ Cp-r ~ /Jxcore/out_ios/ios/bin jxcore-cordova/io. jxcore. node/

5. add ios platform for cordova

The code is as follows:

$ Cordova platforms add ios
$ Cordova plugin add jxcore-cordova/io. jxcore. node/
$ Cordova build
$ Cordova run ios

If a build error occurs, "C does not support default arguments"

You only need to remove the default value to solve the problem.


The code is as follows:

JX_SetString (JXValue * value, const char * val, const int32_t length = 0 );


The code is as follows:

JX_SetString (JXValue * value, const char * val, const int32_t length );


6. you can see the running interface of cordova.
7. add nodejs server in Resources/jxcore_app/app. js

Add the following code at the end of app. js:

The code is as follows:

Function getIP (){
Var OS = require ('OS ');
Var nets = OS. networkInterfaces ();
Console. log (nets );
For (var a in nets ){
Var ifaces = nets [a];
For (var o in ifaces ){
If (ifaces [o]. family = "IPv4 "&&! Ifaces [o]. internal) {return ifaces [o]. address ;}
Return null;
Var ip = getIP ();
If (! Ip ){
Console. error ("You shoshould connect to a network! ");

Var http = require ('http ');
Http. createServer (function (req, res ){
Res. writeHead (200 ,{
'Content-type': 'Text/plain'
Var cur_client = "";
If (req. connection & req. connection. remoteAddress ){
Console. log (req. connection. remoteAddress );
Cur_client = req. connection. remoteAddress;
} Else if (req. headers ){
Console. log ("request header X-Forwarded-");
Console. log (req. headers ['X-Forwarded-For ']);
Cur_client = req. headers ['X-Forwarded-For '];
Cordova ('log'). call ('client ('+ cur_client +') come ');
Res. end ('Hello' + cur_client + ', I am server on iphone app (' + ip + ').' + Date. now () + '\ n ');
}). Listen (1337, ip );
Console. log ('server running at http: // '+ ip +': 1337 /');

Run the program to view the iphone ip address in the xcode log information, and then browse the webpage through the webpage.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.