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.
Related
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.
I'm working on an App that I've made for both iOS and Android. On the iOS side, I use a constant TCP connection and JSON messages for the push notifications. I want to do the same thing for the android version, however I'm not sure if it's possible. I think using the Cloud Connection Server http://developer.android.com/google/gcm/ccs.html is the way to go, however it only shows samples for Java and Python. Is it possible to use this in c++?
You can choose whatever programming language to desire to implement the server side. The question is whether you can find an easy to use XMPP C++ library for connecting to the Cloud Connection Server.
I assume it will be easier to find an HTTP C++ library for sending HTTP requests to the GCM HTTP Connection Server. If you are not planning to use the upstream functionality (device to cloud), you don't need to go though the trouble of implementing/using the XMPP protocol.
what is the best way to create a two way constant communication between a server and an android app?
When I say constant communication, I mean client asking server for data or server constantly pushing data to clients.
From what I saw, I can't use websockets since they are designer for server/browser setups. Is that right? If so, what is the alternative?
Is there free frameworks to work with this in Android?
What I am trying to do is an application that works like a chatting but for multiple people. So they all will get in one "room or channel" on their devices, and then interact with each other, in a way handdled by the server.
Thanks!
As far as I know , one possible way is using a web service where the client can connect to the server , if the web service is RESTFul there are many libraries to access it , one of them is the apache HTTPClient , for the server pushing the only way I know is C2DM for pushing data to clients.
For continuously-open data connection, you may use Sockets. But you should also consider the fact that an always-open connection will drain your battery quickly too. For more details, read this and this
You may want to look at AutobahnAndroid:
https://github.com/tavendo/AutobahnAndroid
which provides native Android/Java WebSocket client framework (plus WAMP = PubSub/RPC over WebSocket .. http://wamp.ws).
This is fully interoperable with WebSocket servers that server browser clients.
The AutobahnXX libraries (where XX = Python, JS, Android) are Open-Source (Apache 2.0). We (Tavendo) are offering a commercial virtual appliance based on Autobahn: http://autobahn.ws
Disclaimer: I am author of Autobahn and work for Tavendo.
But keeping the connection running on the background on iOS and Android devices does drain the battery, for people who have this issue, I suggest using push notifications when the app is not on the foreground.
From what I saw, I can't use websockets since they are designer for
server/browser setups. Is that right? If so, what is the alternative?
Websocket is an IETF/W3C protocol, so it is not confined to a specific client platform. You can use Android websocket to get a two-way communication between Android and server side. For Android websocket client, I recommend using AndroidAsync. It has all websocket API that you need to establish the communication link and exchange data between Android and the server.
I'm posting this here because the thread I made on programmers stackexchange didn't get any answer and I need an answer for this rather fast, so here we go:
For a school project we are looking to implement push like technologies in our Android app, we need to send push messages from a server (Tomcat) to the Phone (Android).
After doing some research I've found that XMPP would be a good option for achieving this type of push notifications, now my problem is how I should integrate this with our Tomcat server where all the information and events will happen as well as where all our other pages are.
Is it at all possible to have a XMPP server or module running inside of Tomcat or can I build my own lightweight module(I was thinking something like a servlet) to handle this?
If you have any better ideas on how to achieve push notifications I would be really glad to hear them, whether it be using a totally different approach then XMPP (I've looked at long polling, MQTT and some other things) or some other way to integrate the solution into Tomcat.
The requirements we have is that we must use Tomcat and Android 2.1 (so C2DM is not an option) and set up push notifications between these.
You can probably run some servers within Tomcat, but I don't think you really gain anything from this setup with respect to XMPP. You will in effect have a server running inside of another server.
The only advantage I can see with this is if you want access to the server internals from some other web application, but for that I would either make the web app another client, or build a custom communication module in the xmpp server that the web app can use to communicate outside of standard XMPP.
I am looking to leverage my existing (and quite simple) NodeJS+SocketIO server application with a new Android based client. This is not using the WebKit browser, but a native WebSocket client within the Android SDK.
I have found the library "Weberknecht" and loaded it into my Android project, and when I attempt a connection to the WebSocket URL I see a "WARN - client not handshaken client should reconnect" message in my NodeJS trace.
Presumably the SocketIO framework does some extra work pre-WebSocket and that is why I am having issues. Has anyone else done this kind of "cross-library" work against SocketIO, and if so could you offer any assistance please.
There is already a Java client for Socket.IO, you can look at the different port at the wiki page. Also, there is a description of the socket.IO protocol on the wiki page.
It seems like the first thing that Java port does when it connects is that it sends a "1::(path)" connect message. Are you sending the connect message?
If you are still looking for an answer, then checkout out https://github.com/koush/android-websockets, which got released recently. It has full support for socket.io server running in node.js