WiFi-Direct communication between Mac/Windows and Android - android

Is it possible to let an Android (>4.0) device establish a WiFi-Direct connection with a Mac OS or Windows device?

According to the Wifi-Direct Docs the protocol allows:
Android 4.0 (API level 14) or later devices with the appropriate hardware to connect directly to each other via Wi-Fi
It doesn't look like Google provides this functionality via the API. Although WiFi-Direct isn't a proprietary protocol and could be implemented for any platform. There are a few posts around the web of people trying to get Wifi-Direct to work under windows:
Broadcast message from Desktop PC to Android Device using WIFI connectivity
https://superuser.com/questions/417888/how-do-i-connect-a-laptop-running-windows-7-to-an-android-phone-using-wifi-direct
http://www.intel.com/content/www/us/en/wireless-products/my-wifi-technology.html
http://androidforums.com/android-lounge/552970-howto-wifi-direct-use-your-laptop-desktop-softap-android-reverse-tethering.html

All you need is to use java.net.Socket. Depends on what do you mean by establish direct connection. TCP connection is established when on destination device (windows or mac) you open listening socket by ServerSocket. On other device you can use Socket with destination address. Of course, windows or mac box will propably have to open that port in firewall.
I guess what you actually need to know is how to get name of target computer or how to discover computers on local network. Unfortunately, it does not depend on android version I think. You should check http://en.wikipedia.org/wiki/Zero_configuration_networking about some hints. I fear there might be problem in need to open privileged port on android, as normally you have to be root for that. And that would require rooted android.
Of course you should specify what do you intend with that direct connection and what software do you need. If both ends have your application, you can just open any not allocated and unpriviledged port on android. Use UDP to broadcast periodically name of android device (propably ask user to enter name of his device). Use multicast to send requests, and receive replies the same way. Multicast sending and receiving would require your application on android and on windows and on mac also. Now you can read from multicast application what type of machine it is, and what local port it left open for your direct connection. From source of udp message you know where to connect.
You may use some framework to speed things up. All this require some knowledge about networking, but I don't know simpler and well working solution. Unless you provide details about what is your direct connection to do.

Related

Which ports are used on Android when listening to socket.io on a server

So let's say I make an Android app and I start the socket.io connection by letting it listen to my API on api.example.com. The API is set up to listen to port 3004.
Does this mean that the Android device itself will open up port 3004 in order to use socket.io?
The reason I am asking is because of a customer that has high security standards, and they want to know which ports are required to be opened in order to use our application.
No it doesn't. I mean Android client will open a port up but unlike server it is not constant. You see unlike server's port, client's port is determined when you connect to a socket server and it may be different every time you connect to one. So it is impossible to say which port however you can use tools like wireshark to monitor and find the port of a specific connection.

Is it possible to a establish a TCP/IP connection over bluetooth?

Well, the following situation: Devices need to communicate offline. The only option is Bluetooth. Here, the issue is that Bluetooth's encryption is insecure and broken. See KNOB attack.
Therefore, I'm looking for a way to securely exchange data between two bluetooth devices (e.g.,Android and iOS). My current guess is to establish a TCP/IP connection to make use of typical SSL/TLS libraries with all its other advantages (certificate check etc.) and disable bluetooth's encryption for performance increase.
https://developer.android.com/reference/android/bluetooth/BluetoothSocket
Unfortunately, it appears that this idea is already not supported by Android. They do offer some sort of BluetoothSocket, but that is not a TCP/IP connection afaik. Does anyone know a way to enable a TCP/IP connection between two bluetooth devices? Any other idea to secure that broken bluetooth connection?
Answer is yes. Nevertheless, there is no usable API on Android (before Android 9 via reflections maybe) and it still has the hide annotation on Android 11 in its source code, besides the requirement of a special permission to be used by system apps only.
The only option is to enable Bluetooth tethering via system settings (if available). Next devices connecting over Bluetooth will get an IP address, while the smartphone acts as the router. The access of services on the smartphone is permitted.

How to start a local network connection programmatically via Wi-Fi hotspot on Android?

I want to start a local network connection using the built-in Wi-Fi hotspot on Android devices.
Is there a way to accomplish it?
And how to communicate between two devices?
EDIT:
I want to do it programmatically. Then I can transfer my own data between devices.
I haven't done this before, so my answer is all theoretical.
I think what you need to do is declare one device the server and start its hotspot manually with a known name.
Start / stop built-in Wi-Fi / USB tethering from code? (According to this question, you can't start hotspot programatically).
Once you have the hotspot set up, you start up the server app and wait for incoming connections. The server app can show you the ip address or hostname.
On the clients, you can do a simple check and see if the hotspot name is around and automatically connect to it if you find it. See this link for connecting to a network:
Using WifiManager to connect to a network
As for your second question, how to communicate - you need to establish a connection between the devices. For this, you need the ip address of the server. The simplest thing to do would be to show the ip address on the server UI and then manually enter it on the clients and press connect. It would then establish a connection to the server on a known port and you can send messages between client and server.
For reference, I found NanoHttpd, which is a webserver for Android. It uses ServerSocket to listen for incoming connections.
Possible answers:
Before ICS and non rooted devices
There is no way you can connect to a device over wifi. There is no API to do. Bluetooth is your best option or user interaction.
Before ICS and rooted devices
I am not sure if someone hacked the code, but when I tried to do an automatic connection to a wifi spot I noticed:
The api is hidden inside the SDK.
The method that does the connection checks the thread who ask for it. If it's not the os thread, it throws an exception.
Using ICS
With ICS there is a new way to connect devices through wifi called Wi-Fi Direct.
Here is a link with some demos.
If you are going to develop your own application for each and every individual terminals(devices) then i think for you socket programming will do the trick .
Yes , android supports socket programming in the same was as java socket programming .
1st google java socket programming tutorials and then you can using the same knowledge in android .
Also do remember to include the uses internet permission in the manifest , actually thats something which ate my brains for a long time :)
You mean communication between wifi enabled devices without any server like p2p? if so its wifi direct which is supported in ICS check this out http://developer.android.com/reference/android/net/wifi/p2p/package-summary.html
Before ICS there is no standard android API for wifi direct, though Galaxy S2 has wifi direct it uses proprietary API's which 3rd party devs can't use.
i dont know programmically create wify LAN,but you can create wify LAN manually,then you can do java tcp/udp program as said by brianestey
"As for your second question, how to communicate - you need to establish a connection between the devices. For this, you need the ip address of the server. The simplest thing to do would be to show the ip address on the server UI and then manually enter it on the clients and press connect. It would then establish a connection to the server on a known port and you can send messages between client and server."
for manual connection follow the steps
take settings/wireless&networks/portable wi-fi hotspot settings from any one of the phone
create new hotspot and turn on wi-fi portable hotspot from there
connect all other device to that hotspot including your pc
you will get ip of each device programmically (includig pc,but i dont know)

Android 2.2. How to set up serial port(com,rfcomm) port?

I a trying to connect my Nexus One with Android version 2.2.1 with my pc and use a terminal program such as windows terminal or hyper terminal to communicate. To do this I believe I need to set up an outgoing serial com port. I have paired the devices. When I go on my PC to Bluetooth -> settings -> "add com port" the android device does not display.
What am I missing?
Does android 2.2.1 support spp? The documentation says it does.
Do I need to root the android to add spp?
Has anyone succeeded in this?
My final goal is to write an android app that communicates with an old school bluetooth device that requires com ports? Getting the android to communicate with the pc is an interim step.
I have tried everything I can think of in my android app to connect to my pc and android device but have not been successful. My android app is essentially the same as Serial over Bluetooth submitted by xCaffeniated but with fewer comments. Any suggestions?
Try beginning with the BluetoothChat sample application. You will then have to alter the UUID used to the generic SPP UUID,
00001101-0000-1000-8000-00805F9B34FB
From this point you pretty much have everything you need.
I have had issues pairing in the BluetoothChat program. So I was required to pair to my computer using the settings menu and then entering the BluetoothChat Program. In BTChat go to the menu and hit connect to a device, choose your computer. I can only speak for windows XP SP3 which is what I'm using. At this point on my machine I receive a task bar pop up asking me if I would like to allow my device to connect as a serial port. I allow it to. Now your phone is associated as the serial port profile on the computer, which you can associate with a specific com port.
Based on bluetooth spec,
http://www.bluetooth.com/SiteCollectionDocuments/SPP_SPEC_V12.pdf,
2.3 User Requirement, "... Any legacy application may be run on either device, using the virtual serial port as if there were a real serial cable connecting the two devices (with RS232 control signalling)." In 4.3 Remote Port Negotiation, "...There is a requirement to do so if the API to the RFCOMM adaptation layer exposes to those settings (e.g. baud rate, parity)... RFCOMM as such will not artificially limit the throughput based on baud rate settings,..."
In my opinion, since Android (2.2) offers no APIs to set up and open a serial port, they may not be necessary as long as you can discover the remote BT device and make a connection to it. I have tried it and it seems working with:
...
sock = device.createRfcommSocketToServiceRecord(myUUID);
sock.connect();
...
where final UUID myUUID= UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"); You may need to take care of Bluetooth Permission and Setup in your application as described in
http://developer.android.com/guide/topics/wireless/bluetooth.html
There might be some issues with the connect() call, i.e. Service is not available or connect is refused, which could be resolved by making sure:
The remote BT device be discovered, and
It must be set to use PIN code (for instance 0000), and
It must be paired successfully with your Android device
These steps must be completed prior to running your application (which has connect call).
Hope this help.
George
There is definitely some funny business regarding how the AT set is implemented on the AOS. The problem is that it is hard to know if you're actually talking directly to Modem or through several abstraction layers (more likely). For a best up-to-date review of the AT Commands available on the AOS platform, plus HW, please see the post:
"How to talk to the Modem with AT commands"
http://forum.xda-developers.com/showthread.php?t=1471241

TCP connection from phone to debugging host

I'm developing client/server software for Android.
While connected to the phone via USB debugging, I'd like to access the webserver I'm running on my developement PC - using the USB connection.
Is that possible and if so, how ?
I stumbled upon the answer after a night sleep.
Enabling USB tethering on my phone (N1, 2.2.1) gives it and the host computer an IP address. The phone can communicate with my web server running on my developement machine!
(Chris, the rumors are right)
Just make sure your web server is listening on that IP address. For apache, use the line
Listen 80
or
Listen x.x.x.x:80
(x.x.x.x being address of your android tunnel)
The easiest way to do it is via wireless. If you don't have wireless, I'd say bite the bullet and get it, it's going to be a necessity for testing anyway :)
Typically the USB only supports connections from the development machine to the phone (via adb port forwards) and not the other way around. Of course once a connection is created data can move bidirectionally. One could use this to build a tunneling proxy web proxy (one connection in from the development machine to a daemon running on the phone, outbound connections from the phone then tunnel through this)
I have heard rumors though that what you want to do - often called reverse tethering - may be supported in some more recent devices.
Kevin's wifi suggestion may be the simplest with a real device.
On the other hand, unlike typical phones, the android emulator can directly access the development machine's loopback interface at an alias address given in the documentation.

Categories

Resources