NodeJS script on Azure VM - android

I've setup a Linux VM on Azure which has NodeJS and MongoDB installed.
Then I have a single node script that I need to be constantly running (it receives and sends Google push notifications generated from an Android app and saves to my MongoDB accordingly).
So far the only way I can get it to run is by connecting via ssh on my local machine, running the script with "node gcm.js", which works fine. But when I disconnect from the server the script stops running... So how do I run it without needing to connect with my local machine? A cron job that starts just one time? Or have I gone about this in completely the wrong way?

Per my experience, there is a simple way for keeping the current process running as a background job.
Here is the steps below.
Connecting via ssh on local machine, then running the script node gcm.js.
Enter Ctrl+Z for stoping the current process, then you will see below, the N number of the [N]+ below is the job id.
^Z
[N]+ Stopped node gcm.js
Enter bg %N to convert the N job from a stoped foregroud job into a background job.
Enter disown -h %N to remove the N job from the job list of the current shell, then the process will be running after closing the current ssh connection.
More details for these linux commands, I think you can easily get via search engine.
Hope it helps.

Related

Running Genymotion in the cloud - EC2 Instance

I am looking to test my application on an android device but also need to be able to install things like nodejs, mongo, ruby to name but a few. Basically my application sends data to an endpoint (mongo) and then i assert that they are there with some cucumber tests.
So i have come across Genymotion On Demand which looks like it could work but was wondering how i can use the app to send data to an endpoint on another EC2 instance and also control the app (say restart it via the command line), again in this separate instance
Has anyone done this or can point me in the right direction please ?
Thanks
You should have no problem contacting the server instance from the Genymotion on demand instance using its private IP address if it is in the same network, or its public IP address otherwise.
For the second part of the question: from your linux instance (with mongo nodejs & ruby), you can use adb to interact with the Genymotion instance. This will allow you to control the app, inside the instance, using 'am' command line tool. See https://developer.android.com/studio/command-line/adb.html#am on how to start your application by sending an intent. If you need a tutorial on how to start the adb server in the Genymotion on demand instance, please see https://www.genymotion.com/help/on-demand/tutorial/enable-disable-adb/.
On a side note, you can even dynamically spawn/shutdown Genymotion On Demand instances from your linux instance using the AWS SDK or cli.

Would running an ethereum node of a private network in android drain battery?

I am building an android application where users can pay for items they buy with ether. Application will use a private ethereum network.
As I understood, I have to run an ethereum node in the android device as a separate process and my android app has to communicate with it using either sending commands or through JSON RPC.
Since android is very concerned about the power consumption, would android allow running a separate process continuously? Would android kill the process after some time?
Also, would running the node continuously in the device cause a huge battery drain?
Yes, it would. You have basicly two options, create a centralized server/client setup, where you android app does JSON RPC queries to a HttpProvider which you set up for your specific app, or you run a light client.
I think, the way to go is to run a light client (LES protocol) which only connects to a full node if required. The light clients are currently heavily developed and there is some beta testing going on already.
Check out the light client roadmap. In june the light client testing was opened to the public. You can test it by running a fork of the go-ethereum client.
git clone -b light-stable https://github.com/zsfelfoldi/go-ethereum.git
build it with Go 1.6 (won't compile with earlier versions)
add the --light flag for light client mode (run geth --light console for console mode)
you can also run it on the testnet by specifying the --testnet flag or the original unforked "classic" chain with the --oppose-dao-fork flag
you can run the light client with the same (default) data directory you use with the normal client, it uses a separate "lightchaindata" database directory instead of the standard "chaindata" so it won't interfere with your regular chain database (can't run the two simultaneously with the same datadir though).
initial syncing starts from a trusted checkpoint (later this will be implemented in a trustless way). Past headers are still accessible on-demand. Trusted checkpoints are hardcoded into the source both for the mainnet and testnet.
There is a dedicated gitter channel where you can ask questions.

Unresponsive Appium Server & Device Offline problems

Below are some common problem encountered when performing tests using Appium with Selenium - especially when running the tests for hours.
Some common Problems are:
sometimes midway into the tests, appium cannot connect to the Device. Logs say Device is offline (even though the device is online & app is accessible, manually)
sometimes midway into the tests, the chromedriver in the case of webview becomes unresponsive.
Questions:
Keeping the Device Constant - Is there a way to restart the Appium Server and connect it to the existing instance of the Android Device. This way i can resume tests where it abruptly stopped.
Keeping the Appium Server Constant - Is there a way to restart the APP on the Android Device and connect it to the existing instance of the Appium Server Session.
Is there some way to CHECK whether Appium Server and/or Android Device is offline / unresponsive ?
You can check whether device is offline w.r.t appium by hitting adb devices in the command prompt.
If it displays the device only then its online to appium server
If Server becomes unresponsive it might be an intermittent stale session issue. Better to stop and restart server from command prompt by hitting adb kill-server && sudo adb start-server
Few things can help you in minimising these issues drastically:
0. Put no lock and no screen saver on device.
1. Always start appium server before starting all tests, in case of testNG/junit framework, start in #BeforeClass or #BeforeTest method.
2. add this capabilities.setCapability("newCommandTimeout", "120") to appium driver, this will stop appium to timeout early thus avoiding nosessionfound exception etc.
3. assuming you are using appium v16 and latest chromedriver v20:
Problem: Chromedriver normally hangs while switching to and from webview but appium waits for chromedriver to respond until defined timeout and if it doesn't respond, appium gets timeout and then you may see hell lot of new issues like device not online, unknown error etc.
Solution: You can keep monitoring chromedriver, when it stops responding, you can start it programmatically, this way your test will get going.
Readymade solution: Download chromedriverhandler.jar from
1. https://github.com/mi2pankaj/chromeDriverHandler, add to your project,
2. use this in beforeTest/beforeClass or at the start of your test: ChromedriverHandler.chromeDriverHandlerThread().start();
3. use this in afterTest/afterClass or at the end of your test: ChromedriverHandler.chromeDriverHandlerThread().stop();
Hope this helps!!

Getting data from android device and plot in browser

I am trying to get data from app running on android device and plot it in a browser running on PC.
I considered below methods
Method 1
Write data from android app to cirular files[ file1.txt -> file2.txt -> file3.txt -> file1.txt ] at regular intervals, in my case 1 sec.
Pull the files using adb in circular order.
Again use the same circular order in reading files in browser using XMLHttpRequest and plot using some javascript.
Here I am facing some error while reading the file using XMLHttpRequest, there may be a issue of synchronisation -> reading and writing of the files.
I think this is very naive approach.
Method 2
I considered one more option of using USB tethering to establish a TCP connection between device and PC and get data from the APP from client-socket running on PC. ( This method sounds better than writing data into files in the device and pulling files using adb ).
Still unable to find a way to send the data received from device to browser for plotting.
Constraints
I am not allowed to use any kind of webserver on the device side.
Any method I think of has some kind of ping-pong/circular approach somewhere in the process, which I think is not a good option.
I know this sounds like pretty simple problem to many of you.
It will be of great help, if anybody gives some elegant approach.
I could able to find answer in some form.
Open TCP/UDP connection from the app running on Device to PC to which it is connected (using USB) and send data.
a) If data has to be processed, process that data in another application and send the processed data to node.js running on PC
b) If there is no processing required directly send data from Device to node.js
Open websocket in node.js and send that data to browser running on another PC.

Problems transfering data between an application and a server using TCP sockets [Android]

My development team and I, are working on an application that uses a sql database, we try to transfer a database from our application to a server using tcp sockets, we made some research about sockets, the server program is written on java language using netbeans, and the application is written on eclipse.
We made several conectivity tests between the application and server programs, using the android emulator, we tried to made it local (running both programs on the same computer) and the server conects with the application, but it doesn´t receive all packages, it receives aproximately 2Kb (we want to transfer a 25Kb file), the same happens when we run the server on other computer in the same network, we made some tests using wireshark to capture all the packagesincoming from the application to the server and viceversa, we´ve noticed that the server receives all the data, but first it receives a 2Kb packet, after that server application receives an end ack, and then, the application receives the missing packages, and then discards them.
We also made some conectivity tests using a coby kyros tablet instead of the emulator, and we have no problem, the application running on the tablet, sends all the data, and the server receives it.
We want know if there are an error on the emulator, and how to solve it.
Please help us or send us yout feedback
This sounds like you are running into a configuration problem with your emulator environment. Take a look at the network configuration info for the emulator.
The fact that its working fine from the actual device suggests to me you have an emulator network configuration issue. There could be a number of issues. I imagine that wireshark can show the packets reaching the machine the emulator is on, but that doesn't mean they are making it into the virtual network the emulator is in.
To verify you'll probably need to use something like
telnet localhost <emulator port>
network capture start
... run test ...
network capture stop
and then look at the capture file. That seems like it should capture your traffic inside the emulator environment to give you an idea of whats happening.

Categories

Resources