I'm totally new to network sockets so any help is appreciated.
I'd like to know how to setup a network socket on an Android device and use it to pass data generated by an App to another App on the device.
This is because the App receiving the Data will at some point have to be able to receive data from an external source, so I'd like to build in the basics of this before I get to that point.
Any example code etc. would be great and I'll edit my question as I go if required.
I don't think using sockets can solve your problem. Only one app can be active at a given time, and the connection won't work. Unless you create some sort of service, but this approach seems wrong.
I believe you have 2 basic options in front of you:
A server that both apps communicate with.
Writing information to the disk in a globally readable place.
The server option is better IMO.
Related
For mobile development i woud like to move something on the screen on a mobile device and on another mobile device you see the same object moving.
What would be my best option to use to exchange this data? I thought about firebase but the problem is you move the image alot of times so you easily get to the 50000 limit within an hour. also the fact that saving an position is abit odd to do in a database.
My second option would be using netty framework. I thought about using their socketstream option. My question about this is, my school stresses the use of an api between data exchange but is that also possible here? or is that more for webdevelopment?
In summery, What would be the best option to use for data exchange if you need to send alot of small request. If you sockets/nio framework is it normal to put an api between the client and server?
I thought about firebase but the problem is...
You don’t need a database because you don’t want to save the object’s position. This data is not valuable to you (right?).
You need to pass data from one device to the other to see the object moving. This can be done by establishing a network between these two devices. This can be done using sockets.
If you sockets/nio framework is it normal to put an api between the
client and server?
If this API use sockets under the hood to simplify a client/server implementation for example then it’s not a good idea to use sockets. They’ve already being used by the API.
On the other hand if the API does need socket implementation from your part to be used correctly, like the android Bluetooth API, then yes it’s normal.
Your use case
You can do this by connecting the two devices on the same network and transmit freely any data you like.
If this network doesn’t need to be the Internet then you may want to transmit data over
Bluetooth
WiFi p2p
or your local WiFi using NSD
For these and more see Android Connectivity.
Im a little new to the android development, I believe I have the basics down but I am wondering the best way to communicate between two phones running the same app. I am looking for something that would be close to instant. For an example, if you sent a message or somekind of variable or string it would appear on the other phones app providing the app was open on both phones. Would be great if I could be pointed in the correct direction here, Thank you!
Assuming you have access to a server that both devices can connect to, the best way to handle this is to set up a socket and have both devices connect to it. That way the messages can be send back and forth and be pushed through immediately (rather than the devices polling for any new thing to do intermittently).
You can learn more about using sockets on android here: http://developer.android.com/reference/java/net/Socket.html
If you're unfamiliar with how to write a server socket, you can write something that works somewhat similarly with a system that just has each device leave a message and have the other device come looking for it, but as I said, that is much less "real time" since then you have to have the devices constantly pestering the server to see if there's anything new to do.
There are also kludgy ways to create a fake socket behavior whereby the http connection never closes and you just keep sending data down the pipe, but if you can avoid it and just use a socket, you should.
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.
Does anyone know how to implement communication between 2 android devices over the internet without using App Engine? For example, I have 2 Android devices, and I want to send a stream of data from one to the second one over the internet. I would like to know, if someone could give me an idea, how could I identify the second device (or how to create a communication channel between two devices ), so I could initiate the transfer (this is not possible using IP addresses ?).If i were to have my own server, which is the best way to go to accomplish this? If someone could point me to some useful resources I would be grateful.I have some background on android programming.
One way I was thinking to accomplish this was to write an android application, and when the user enters it, it will start a service. This service will then listen for network events and registers on my own server with the username and the IP address of the device as available.When another device wants to send data, it will connect to the server, search for the target device (by username key), gets the IP address and sends the data. Could this work, or does anybody have other suggestions?
One way I thought about doing this is making
(excuse the spelling mistakes if any)
It would help if we knew what kind of data you were trying to transfer.
For small bits of information, like notifications, events, and the like, I would suggest doing an HTTP POST to a server that has C2DM capabilities, and using the server as an intermediary.
For larger data, the only way I can think of to do it is to set up a SyncAdapter, then upload the information to the server. The delay will be a bit longer, but you'll reliably get the information downloaded from the server to the phone. So less of a communication API and more of a dropbox for phones.
I haven't done much with NFC, but that may be something you want to look into.
I was wondering what the simplest program for sending an object from my Android phone to my computer wirelessly (via LAN) would be. I have created Java RMI programs with a server and multiple clients, so I have a grasp of the concept. However with android I'm just not sure where to start.
What I am aiming to do is send some sort of information (could simply be text) to my computer and my computer will do an action. I have the GUI interface's and the actions to be carried out all worked out, just the sending of some sort of information is getting me.
Could anyone help me out?
I would say it's not much different from sending data between regular computers. Basically you have the same options. Unless you have some special requirements, the most straight forward solution would be to just set up a ordinary server / socket.
A tutorial on the basics (including example code): http://www.ryerson.ca/~dgrimsha/courses/cps841/serverSockets.html