Android server-initiated TCP connection - android

I am new to Android development and I would like to know if there is any way to establish a server-initiated tcp connection on an Android device.
What I'm trying to achieve is making an external server able to access data from the Android phone at any time without using a battery-draining permanent connection.
As it is not possible for the phone to do something similar to an accept() when it is on 3G, I was wondering if there might be a system of "hidden" notifications that could be used to tell the phone to connect to the server.
Another option would be for the phone to try a connection every X seconds but I don't like the idea, and I'd rather have the connection to be created as soon as it's needed.
Are there any 'clean' solutions to do this?

You may want to have a look at the Google Cloud Messaging for Android.

Related

Sending Data from Android Device to a RaspberryPi

I need some help in terms of choosing a design option for my problem.
I currently managed to implement a RaspberryPi acting as a Server and my local machine to act as the client. This client send JSON-Data to the Server which processes these. Everything is working as expected and I am using TCP-Sockets for the communication.
My problem:
The next step of my project will be, that I will use instead of a PC an Android-Device as client. What I want to achieve is, to send data to the server on the go. What I mean by that is, I do not want to restrict the server to be in a special network neither the client. What can be expected, is that server and client are next to each other, like in the range of a bluetooth connection. My question is, is there a relatively simple way to implement this communication? Is TCP a possible solution for this (even working in mobile networks?) or do I need to use Bluetooth, or is the way to go, to create some kind of network the client/server connects to and communicate here?
Sorry for propably stupid questions, but I am new to all this network stuff.
EDIT:
Since there were no respones, maybe I can do a more precise question. Is there a proper way to scan a network for a device name?
The only way I currently can imagine is to do a bruteforce like check on every IP-Address and resolve the names?
I first tried to let the Pi host an ad-hoc network, but it seems that non-rooted android smartphones do not have the possibility to access ad-hoc networks.
Therefore I made the Pi acting as an access point.
The communication now is very simple realized by a tcp server-client system.

Android 3g wifi simultaneously

I am using Android studio 2 and java, and i am writing an app that i need to be connected with a piece of hardware through wifi (parrot ar drone 2) and also "trigger" some events (takeoff land etc) through 3g network. I have made a simple app using parrot sdk that do some simple things to my drone successfully . I am facing now the challenge that these simple things i want to be driven through my server (i am thinking of websockets).
So my problem is :
If my device is connected through wifi to the drone, how could i also connect to the internet in order to get "triggered" to run some commands?
I was thinking that would be great if o could connect my android device to the drone and with some way be connected to internet.
After some research i have found that may be this functionality be available to android 6 BUT i have not found any example yet.
Generally i trying to find a solution (software or hardware).
I appreciate a lot any kind of help or suggestion about my problem.
Thx in advance
I don't think it is possible to connect to 2 W-Lan hotspots simultaneously with just one chip. Where did you find that information?
You can set up your Android device as a WiFi hotspot and have your drone connect to the internet via that.
At the same time your app can connect to the drone, assuming your drone has some sort of local server like connection your app connects to.
You can check this in practice quickly by setting up a Wifi hotspot, connecting your drone and then using a ping utility on the phone to make sure you can ping the drone successfully.
If you want to connect from a remote server to the drone then you are dependent on your network allowing inbound connections, which is often not the case. A common workaround is to use some form of mobile push notifications to send a message to your app asking it to contact a server on the internet, which will then tell it what action you want to perform on the drone. In others words:
send message to server on the internet somewhere to tell drone to take off
your server triggers a push notification to the app on the phone
the app contacts the server and asks 'what is the message for me'
the server responds to the app with the 'tell drone to take off' message
the app messages the drone to tell it to take off

Ways to connect two devices to each other

I want to build an app but first I need to know about all ways that are possible to make a connection with two android devices. Over 3G, Bluetooth, Wi-Fi and etc, where can I get a list of this? (If it exists)
To be more clear, I want the better way to find an X device with my Y device and trade some information between them. It`s important to considerate that two devices need to be close each other.
Like the feature of change Friend Codes with friends on 3DS via LOCAL, got it?
Can anyone help me out with this? Thanks already.
If you want to establish a local connection, the following ways can be used.
Internet (Wifi, 4g, etc.). A webserver should be running and establish a secure connection between the 2 devices.
Bluetooth - An app can be written to establish a local connection to a friend who is running the same app.
NFC - An app can be written to establish a local connection to a friend who is running the same app.

how to make remote control app? where to start?

what is the best framework that I should use to make a remote control app for Android. What I want to do is something like Tony Fadel's app for Android and Iphone where you control your house thermostat temperature remotely with a smartphone app.
I was going to use sockets programming, but not sure if that is the best way. If it is then i will use it, but wanted some feedback before i get started.
If I make one android device the server and the other device the client I will still have to manually set the IP address every time I want to connect the client to the server.
I am trying to avoid having to make a web-app and having to make a php website to act as a server for this. Having to keep a server running is too much overhead. would rather make something like two android phones or tablets that can send message to each other over the internet or wifi router without too much setup and effort.
Would appreciate any ideas on this. I can't figure out how the nest thermostat works (http://www.nest.com/) but that is kind of the functionality that I am looking to copy. I wonder if they have to use a centralized server for all of the remote controls. If there is a way to do this peer to peer that would be great. that way all i would need is two Android tablets.
The other examples I can think of is VOIP like skype and google talk. I am sure these don't use a centralized server for voice calls. My needs are much more simple. no voice or video, only sending text messages from one android device to another over the internet. Each android device will probably be using wifi exclusively.

How to get two android devices talking through an app on a lan using wifi

I have a small project I am working on and one of the technical problems I am running into is finding a easy way to get one app on one android device to push data to another app on another android device via lan.
I do not want to have to resort to the push API or other similar solutions in case there is no Internet connection.
I was wondering if anyone had any suggestions for this.
Thanks.
You could definitely use Java Sockets. Open a ServerSocket on one device and connect to it using a socket on the other device. You can then send and receive whatever data you want.

Categories

Resources