I've faced an issue with creating any kind of servers under Cordova application. Wondering if it possible at all.
Scenario
Let's imagine that we have a decentralized network of devices (tablets, phones) from one tablet to a huge network of 20+ devices and can be more. These devices must handle synchronization between each other and it can be implemented as HTTP server or WebSocket server, etc...
Each device have installed Cordova application and our goal is to make these devices discoverable in a network (I was thinking about UDP datagrams for discovery) and these devices must synchronize data between them (simple TCP connections and JSON objects).
Question
For this scenario we need to have an access to a network layer in Cordova application. So, our Cordova application when running onto device can be as server and as client as well. The question here is how to implement UDP\TCP server in Cordova application, since we have only client implementations?
P.S. I was trying plugins like cordova-plugin-chrome-apps-udp, cordova-plugin-websocket and cordova-plugin-websocket-server but it still doesn't work properly (I'd like to say it's not working at all)
Related
I have a scenario where I should connect and disconnect to several WiFi endpoints from my web application and at the same time expose some REST API's. Since I come from a JVM background, I started writing a Java web application using Spring Boot and when I started to try writing WiFi connections / disconnections, I realized that it is not so easy and I had to do some ugly hacks. So I ditched the JVM and I thought that I could explot Android for this and this API from Android is exactly what I need:
https://developer.android.com/reference/android/net/wifi/WifiManager.html
I now have a Android device and this device would run as my primary server where I would like to run a Web Application that would eventually serve REST styled end points and at the same time manage my WiFi connections. I want to be able to use the Android SDK with which I could connect and disconnect to several WiFi networks, but I'm not sure as to how I could have a HTTP server that runs on Android where I can implement my classical CRUD style web application like I do in Spring Boot.
Any suggestions?
I'm in the process of building a Cordova application that needs to talk to a hardware device I'm building. The device can transmit HTTP requests, but can't accept requests. Both the app and device are the only devices on the local network with no internet access.
Are there anyways for the Cordova application to receive incoming HTTP requests from the hardware device?
If it helps the app needs to support Android (with iOS coming out in the near future).
Found a plugin that does what I need - https://github.com/driftyco/cordova-plugin-discovery
Props to eduyayo for putting me on the right track
I'm having the following scenario:
On the PC i will have a program running: java or .net, haven't decided yet.
When a certain event happens on PC i want to notify the android device.
I want a solution as independent and reliable as possible.
Opening a server on the PC/Android i think is out of the question because the user might be behind a router or on GSM internet (as far as i know it can't open ports as server)
The solution i have at this moment is to have a web server on the internet and have it handle the job, but i'd like not to use this because the delay between checks should be around 5 seconds, and i expect to have about 2-3k users simultaneously, and that will probably know down a regular web server.
So, any ideas how this communication can be made?
You may consider the option of Bluetooth client server application since PC and Android device usually have Bluetooth. You will have a Java server running on the PC and an Android client on the device. Check out this post: Send text through Bluetooth from Java Server to Android Client
You can handle the situation where Bluetooth is not available by creating a failover mechanism using REST API & JSON.
If you're already a web developer, I think creating a light HTTP based REST or JSON service would be a great solution. You've already said you don't want to do that which leaves the option of rolling your own client/server set up.
On the Android side of things, one way to do it would be to use TCP sockets. You can learn more about them here: http://developer.android.com/reference/java/net/Socket.html
I'm building a multi-OS mirroring system which I would like to implement using a hybrid client-server and p2p communication method (at least that's the best way I have of describing it).
My issue is that at some point I have a central server (appengine, so there are limitations to what I could do because of time and networking capability constraints) that would need to get a message to a host of different devices which are not necessarily running the same OS (Windows, Android, iOS, Linux, etc...).
Android and iOS (or any other mobile platform) are the main problems it looks like I will be having on 2 levels.
1 - They are both limited by battery power (more so than a laptop and desktops shouldn't have that issue at all), so whichever method I use needs to take that into account.
2 - NAT (harder because the user has relatively less control over their firewall than on a network that they are running). My central server will maintain a table of which device has what IP address, but from what I understand if there is NAT or a firewall it won't be able to get to it if the port was not forwarded.
Since I will be writing a specific client for each OS I prefer a solution that is more universal. I have been leaning towards writing an extremely simple HTTP server that sits on each client and takes requests (which appengine is able to send) and treats them as messages that alert the client to perform an action (either with the server or another client). However, I run into the issue of NAT/firewall. For instance if appengine needs to send a message to AndroidDevice1 it would grab its IP address from a table and make a request to it. However this doesn't work if the ports aren't forwarded correctly, and if the user is on 3g/4g the firewall is controlled by the data provider.
Because of this, I started thinking about using Android C2DM but I want a solution I could implement across platforms.
The only other method I could think of is to just have the client poll the server for messages. This has the battery and network consumption issue though.
Would there be any other way to implement this, and if not, which one of the above methods are best in terms of balancing usability, power and data consumption and user input (the less the user has to do to get the client set up (ie port forwarding, etc...) the better)? Please note that I do not intend for this to become a discussion/flame war but a logical presentation of facts.
Thanks in advance!
You can create a persistent TCP connection from the device to the server and then communicate over this open connection. This would be a very simple connection with keepalive packets for the most part.
In theory this would consume some battery through the radio, but in practice I have experienced that the battery is not affected much at all. Key is to keep the communication over this line to a minimum.
If AppEngine does not allow this approach, you can run your own socket server and then communicate between this server and the appengine server using REST. A socket server I have used is Apache MINA and had no issues with scalability.
Another problem you will have with this approach or any other approach is that on iOS (afaik) you cannot keep a tcp socket open when the App goes into background. The only thing to communicate with the iOS device is Apple Push Notification Service
I would prefer rather than having HTTP Connection you should create TCP/IP tunnel and make communication fast and reliable. I have one Chat application which runs perfact for me using TCP/IP. If you use this you will have same logic for multiple platforms. Only thing you need to write is different code for iOS and android.
My question is how to create a web service on android device & host it on the mobile device.
I don't want to access an already created webservice deployed on a server; I want to create a webservice that returns json/xml & host it on mobile.
RESTful Web Services Implementations in Mobile Devices says it's doable for Java-based mobile devices, so I think it can be done for Android too.
There is one problem with your setup and mobile devices: mobile networks (wifi and 3g) mostly use NAT, which prevents inbound connections. This makes mobile devices inaccessible from the internet (inbound) while they can still initiate outbound connections. For this reason mobile devices mostly do not host servers.
What you can do is make an Android service which pings a server ( a web-server) every 30 minutes or so simply send a bit from client to server and back to check the availability of request from another phone. This way you can upload media files to server and download them to your another device.
I am trying to solve the same problem and I am leaning towards https://github.com/NanoHttpd/nanohttpd.
It is a tiny webserver without any REST or MVC functionality, thus you would have to write it yourself (MVC, content negotiation, etc).