NodeJS on IOS/Android - android

Maybe what I'm about to ask is stupid, generally I don't have so experience with server-side.
I'm building an Angular web application, with nodeJS on the server-side.
I need that the server (Node.exe) will installed in the device itself (IOS/Android), and nodeJS will open a localhost socket to communicate with the device.
(According to nodeJS official web site, nodeJS only support windows/Mac OS/Linux)
It's possible to do that?
If not, there is another server can I install in the device?

Yes you can with JXCore (a fork of nodejs), more info in this link
Build Mobile Apps with JavaScript and the Node.js Ecosystem repository is in here.
And how to compile it is in here JXCore - How to Compile
But if you need it to be nodejs (not the last version) you can use this link to do what you need Building and running Node.js for Android
UPDATED 27-09-2018
Like someone has pointed out, that project is no longer maintained but I have found and alternative by Using Termux on an Android phone you can use nodejs / gcc / vim / etc and more tools to do many thing
This link show how to do it for nodejs ( and I have tested it on my phone ):
Building a Node.js application on Android - Part 1: Termux, Vim and Node.js
First install termux from playstore, of course.

I don't understand the point of using a server tool on the client side.
If your application should work with an offline mode, you should put all data and other in your client app (using cordova).
If your application works with an online mode the server side is needed to serve your data. Here you can setup a nodeJS API which provides routes for your application to have content to print.
I'm not sure I brought you the wanted answer, so can explain more the point of using a server tool on a client device?

What you are trying to achieve, turns your device into a server.
A server side language is meant to stay on the server.
I don't really see why you need to open a localhost socket on the device to communicate with itself. Is it for offline testing? You can do that since you have a computer and a device, and both are connected to the same network.
I believe a really good start would be understanding the concept of the Client-Server architecture first.
But in short, the proper way of implementing a Client-Server app using your chosen technologies would be:
A server should provide the client with answers to his requests.
So in Node.js (server-side), write whatever you want to communicate with your database (Create, Read, Update, Delete), do custom processing, etc...
and return a structured answer.
The client is expecting answers to his requests, and is supposed to handle the answers in code. So the program written in AngularJS (which is your client-side language) will be installed on devices.
The client has to know the format of the server's answer. Is it plain text? XML? JSON? ...

so you mean you would like to have an app can run some services via http?
not sure if iOS allows application with JS virtual machine executing code ...
and for Android
searching on Github and I find how to build NodeJS for Android
https://github.com/dna2github/dna2oslab/tree/master/android/build
Here is an example to run compiled Nginx binary on Android at https://github.com/dna2github/dna2mtgol/tree/master/fileShare
You may modify a little more to replace Nginx to NodeJS. The code to run Nginx is not very nice; maybe you can try an Android Service to let the server run on backend on Android device.
Hope it is what you want.

Related

Sending Requests to Locally-hosted OpenSips Server using android

I am really new to opensips and lately I was able to install the OpenSip server on my VirtualBox based VM ( Debian 10). Now I want to create an android application which enables SIP calling (Push to talk app) using that locally hosted OpenSip server.
I tried to understand the documentation on the OpenSips, but it is really tough for me. For now, to make sure that my OpenSip server is finely running and handling the SIP calls, can you suggest me a way to test it using an android programme?
Thank you!
Try Linphone - it's an Android based SIP User Agent.

Implement OpenVPN in Android

I recently bought a VPS to create a VPN app but it looks like there is no tutorial anywhere about it.
I saw the ics-OpenVPN project on Github, but I have no idea how to use it!
All I want is to connect to a Linux server from my phone
First of all, install OpenVPN on your VPS server. Although I do not have experience to install OpenVPN on VPS server but I think you can follow this tutorial it looks easy https://www.skysilk.com/blog/2018/install-openvpn-linux-vps/
After complete your installation you will get the .ovpn configuration file. Now to connect with your VPN server from your android app you need an android client software like the ics-OpenVPN android client.
I have also developed an android VPN app based on OpenVPN library you can use my source code it is open source. The instruction of changing .ovpn file is given on the GitHub repository.
Github: https://github.com/ashraf789/Cake-VPN
Do it has to be VPN? Or does an sshconnection with porttunnel satisfy your needs? That is for example how i connect to services on remote servers. With the tunneled port you are able to map the port on the remote server to your local system and access via localhost:.

Running python script on EC2 using an android app

I have an android app that must execute python code in ec2 on demand. What is the best way to implement this?
Have a look at the remote management tool that amazon provides.
You can have you servers setup with the tools,the ssm agent and the script you need to execute. Then send a remote command to them through the sdk.
Check the related ssm java sdk and how you can utilize it with android.
Step to get started with Python as backend and Android:
Install MAMP, WAMP or LAMP etc on your local computer depending on OS. Install python separately if it's not already included.
Introduction to Flask and RESTful services : follow https://blog.miguelgrinberg.com/post/designing-a-restful-api-with-python-and-flask.
Maintain your code in version control eg Git. It is also useful to streamline your code upload from local to server.
Get a server : Since you might have to install some modules/packages on your server I recommend to have server with root access. You can try AWS free tier for 12 months.
Install Apache/Ngnix, python, SQL, phpmyadmin and Git depending on OS you have bought from AWS to start serving.
Go to your server root (mostly /var/www/html/) and git clone your project repository and change your environment variables and configuration as per step 5.
Ideally you should check here that you are getting expected response for your requests . Use Postman to test post requests.
Now you can consume your web service on android using any networking library like retrofit or volley.
Let me know if you need clarity on any point. Happy coding.

Using MongoDB along with ionic android app

I am building an android app using the ionicjs framework. I have done the basic layout using ionic's creator that gives me the code for it when I export it.
Now, I have to authenticate the login and register information against the details in the database, which is MongoDB. My question is, how do I install MongoDB? Do I install via the command prompt like it says in the Mongodb website or do a npm install in the root folder of my project?
After the installation, how do I go about connecting to the DB and doing the authentication? I think I need to use a REST API for that.
It would be very helpful if someone points me in a direction. I am new to developing apps like this.
Thanks!
MongoDb is a server-side database. So you have to install it on a remote machine, You shouldn't connect database directly with the mobile application which runs on clients hand. It's totally insecure, anyone can reveal your database connection information (password, username) by simply decompiling the app.
So, As you figure out, right way is to create a REST API to retrieve and send data back and forth between the server and the application.
Create a backend services with a server-side technology that your are prefer. It could be PHP,Python,Java or whatever. The client side application should not depend on the server-side technology your are using. Server side technology should completely transparent to the client application. You can attain this by designing good REST API.

NodeJS Alternative For Android

I have visited many blogs and questions looking for a way to use android as a client and nodejs as a server for my app. I came up with a solution that is to use PhoneGap like frameworks so that it could act like native but is not in reality. I need to use native android sdk and connect with NodeJS server (using SocketIO) to create my app. Is there any way I could do this?
P.S I want to know that while I set up by GCM can I pass my IP and port that I have created in my socket.io file to the GCM?
Cordova (hence PhoneGap) allows you to use most of the hardware APIs. PhoneGap nowadays is just a build service of some sorts.
The Cordova website and plugin store explain all the details. But t WebSockets are just an upgraded protocol or feature of TCP. Any newer technology supports it without any dependencies, but in dependence of the network you're traveling in.
Without diving deep into the code here at socket.io-website, I reckon that the initial build of your Cordova app is a WebSocket implementation to the server. So you got everything bootstrapped already.
What this tutorial doesn't explain is how to connect to the server. But read it up here.
I have no prior experience but Google Cloud Messaging seems not to be in the scope of the problem of socket.io. Once you have a connection to the socket you can send to the client whatever payload you want and might or might not need GCM anymore. If you need to send stuff via GCM read up on the the GCM node module.
Passing IPs around shouldn't be much of a problem since you're are running a public service anyway. You'd need to secure it anyhow of course.

Categories

Resources