Android is there any way to lock socket with only one device? - android

I am creating a single test application which is using sockets to create a connection between two devices and transfer some data (a kind of messaging app).
My question is:
Is there any way which I won't let other devices connect to a device, when it is already connected with another one. For example I have two devices A and B and they are connected. I don't wanna let device C to connect to any of them.
Any ideas how can I achieve this?

Well, seeing how A and B need to be listening in order for C to connect - i.e. something like ServerSocket, simply stop listening for incoming connections once it successfully makes a connection between A and B?
Without your code for how you connect I can't tell much more, but that should be how to do it.

Related

How to set up One to Many connections without any user interactions

We found multiple ways to connect two device with a Peer-to-Peer connection using things like Bluetooth and Wifi direct. Problem is, each device need the user to accept or confirm the connection.
We would like to make a One to Many system where everyone can connect to one device. This device need to manage all the connections incoming without any user interaction (really independant) and then display in our activity some informations receive from all the connected device.
We're looking for some good examples on how we can do this. Thanks
Cant you just use basic TCP Server?
EDIT/Answer to comment:
Yes it is possible, here is one of my sample apps, tho servers can be created on ports above 1024

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.

Simultaneous Bluetooth Connections on Android or iPhone

Although I feel like this question has been beat to death. I still haven't found a definitive answer. But now, I'm going to try and make things a LITTLE more specific, maybe some of you bluetooth gurus can put it in terms I can understand!
Is it possible to have simultaneous bluetooth connections? For example, phone A sends data to phone B, then B sends that data to phone C, who then sends it back to phone A.
If this is possible, the phones would need to have multiple (at least 2) bluetooth sockets open at one time.
If this is not possible, do you know if it would be possible close a socket, and open another quickly enough to simulate this functionality? (given that the phones are already paired)
Let me know what you think!
Thanks!
For iPhone, you can use GameKit's peer to peer mode for this.. it's a bit confusing but it works:
https://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/GameKit_Guide/GameKitConcepts/GameKitConcepts.html#//apple_ref/doc/uid/TP40008304-CH100-SW1
Client/Server GKSessions
But note that it is not (or nearly not) possible to connect iOS with Android via bluetooth (unless you create an app for jailbroken devices)

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.

Android Bluetooth

How can I remotely start an activity in a different android device using Bluetooth? Is there any way? If so can anyone suggest sample code?
you mean "take control over another phone" in other terms ?
Bluetooth would be the mean of physical connection, but i don't know if implementing your own server on Android and thus handling operations like starting apps and so on would be an easy thing... and i'm voluntarily not speaking about security issues ? any experts in there ?
Yes, you can do this, it's pretty easy once you're familiar with bluetooth. You'll have to make server/client connection on both devices with bluetooth (RFCOMM). The client will send a message to the server (by pressing a button or something), server parses the message and executes (starts a certain activity). Take a look at the BluetoothChat example.

Categories

Resources