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 should connect to a network!”);
return;
}
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-For”);
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/’);
运行程序,即可在xcode的log信息里面看到iphone的ip,然后通过网页就可以浏览网页。









