Running an HTTP Web Application on Android - android

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?

Related

HTTP\WebSocket server under Cordova application

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)

Access REST end point on an embedded device using WiFi direct from android

I have an embedded device that exposes its functionalities via a RESTful Web service. I want to consume those Web services via my android device by connecting my mobile to the embedded device via Wifi? Is it possible to do so?
The possible use cases are transferring the control panel UI of the embedded device to the android and controlling it remotely. The UI is exposed as a REST endpoint.
If the chip you are using supports Wi-Fi Direct, you should search for its code yourself since I don't know about it really, but you can find documentation and examples of wifi direct here, and if it doesn't support it, there are two scenarios, one is that you want to make your android device a server and your chip a client, which leads you to use Nanohttpd in your android code to make a server, and the other one is to bring up a server on your chip and make your android device a client, which leads to using a library like loopj which saves lots of pain. so I guess that was all.

Send data/message from server to android (not using GCM / C2DM)

We have a system running on an Intranet. The android app is running on a PDA client. We facilitate communication using web services done in .NET.
My question, is there a way for the server to send a message to the android app to trigger an action in the PDA (kinda like receiving SMS) ?
Previously, we used sockets since the PDA was running on Windows Mobile (as mentioned we've switched now to using Android). I've read this can be done using Google Cloud Messaging, but the system cannot connect to the internet, hence, I need alternative.
We can go back to using sockets, but I'm worried the battery life would take a huge hit.
Thanks
you can use xmpp protocol to implement this.asmack is a library available for android .(smack is for java which has some issues with android). you can use this on intranet .

ActionScript socket in Android

I have a Flash client application, written in ActionScript, which uses the XMLSocket class to talk to the server device via TCP/IP, on port 5750. So for example, I can run the Flash client in a browser and connect to a server which is on the Internet.
Since recent versions of Android support Flash, I would expect this to work when we install the Flash client on an Android device. However, the connection attempt just hangs. I don't currently have any diagnostics on the client side, just the running Flash application. So we have no logs or standard error messages.
The server device is basically a black box, but it does seem clear that the server never gets the request from the client. This suggests that the client was unable to open the socket.
A basic Web search suggests that not much is known about this situation. Any thoughts about what's going wrong here?
For example, maybe XMLSocket just doesn't work in Android? Or Android blocks port 5750? Or Flash Player has some kind of sandbox or firewall limitations built in?
We've tried a couple of different Android devices running Android 2.2-2.3 and Android Flash Player 10-11. The client is written in ActionScript 2.
This is probably a security settings problem.
I suppose your Flash client running on the Android device is not in the same domain as the server. Adobe's AS2 reference tells it all:
The XMLSocket.connect() method can connect only to computers in the same domain where the SWF file resides. This restriction does not apply to SWF files running off a local disk. (This restriction is identical to the security rules for loadVariables(), XML.sendAndLoad(), and XML.load().) To connect to a server daemon running in a domain other than the one where the SWF resides, you can create a security policy file on the server that allows access from specific domains.
Setting up a server to communicate with the XMLSocket object can be challenging. If your application does not require real-time interactivity, use the loadVariables() function, or Flash HTTP-based XML server connectivity (XML.load(), XML.sendAndLoad(), XML.send()), instead of the XMLSocket class. To use the methods of the XMLSocket class, you must first use the constructor, new XMLSocket, to create an XMLSocket object.
There are a couple of other related problems to your question, worth taking a look:
XMLSocket working in firefox but not IE
Flash client XMLSocket not connecting to server

Android - Create RESTful WebService - Host it on mobile

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).

Categories

Resources