Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
437 views
in Technique[技术] by (71.8m points)

android - Accessing localhost from outside

I have looked for some way to run node.js server on my android device. I found some good article describing it : https://medium.freecodecamp.com/building-a-node-js-application-on-android-part-1-termux-vim-and-node-js-dfa90c28958f#.xrh3v0du1. I have followed the tutorial and installed linux vm on my device and installed node.js. I have successed to run my node.js script and access it from android browser. But I can't find any way to open this page outside my android device by ip address.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can access your localhost android running your Node, if your TelCo allow, following the below steps. Note: this is only valid when your mobile is connected using your phone data-plan (2-3-4-5... G data), and not when it's using a wi-fi connection. To be clear: your app, on your mobile, only serves content, by the below method, if this mobile is not using wi-fi data.

1 - setup an account in a dynamic dns provider website (good plans are always paid). There you will configure an URL like http://muhlinin.mydyndns.com which will be pointing to a dynamic IP number;

2 - install the respective dynamic dns app into your mobile, this app will forward your current IP number to your dynamic dns account, something that assures every request to http://muhlinin.mydyndns.com always will find your mobile to respond to that request, whatever IP your mobile has at the request time;

3 - on your android, running (for example) Termux and Node, make your .js server script listen to a not default port (cause the default, 80, may be closed by your TelCo), for example, 8000, on the dynamic url you got following itens 1 and 2 showed above. Something like this: http://muhlinin.mydyndns.com:8000

Of course, if your mobile turns off, or the respective dyn dns app is closed or not started, or your Node server is closed or not started, every call to http://muhlinin.mydyndns.com:8000 will result in error. So, in order to have everything working, you have to have the previous 3 steps done correctly and all opened and started on your mobile server:

1 - dyn dns app;

2 - Node.js runtime;

3 - your serverscript.js (which you will start by doing a simple 'node serverscript.js' on Termux.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...