Android adb forward and own bridge to reach remote server - android

i have a question about the adb forwarder stuff
My situation:
Ressources: 1 Windows PC where i write my code, 1 Android device (Android 2.2) connected via USB to the Windows PC, 1 Linux Server running inside a virtual Machine (VMWare) on the Windows PC
Task: the android device has to connect the virtual Machine via TCP (Port 65001)
restrictions: I am not allowed to use wlan for that (because of some issues that i can't influence). I am not able to do usb (reverse) tethering because my devices does not have the usb tethering option in the android menu (disabled by the manufacturer).
I am able to telnet the port to the virtual machine (telnet 192.168.1.2 65001) and get my data. So there are no network problems between local and virtual machine. The local ip address is 192.168.1.1.
Now i need a bridge from the incoming port 65000 to the listening Port on the virtual machine (65001). I have used the following command adb forward tcp:65000 tcp:65000 to get a tcp connection over usb from my android device to my localhost (and vice versa). As I know you can't forward with adb to a remote machine.
Now the problem is that i can't bridge from 127.0.0.1:65000 to any other port to get the full communication path. If I try to create a listening connection on 127.0.0.1:6500 i get an error with the message that the port is already bind (because of adb forward tcp:65000 tcp:65000). If the forward blocks all other connection on this port, how can i get the incoming data from the android device?
I've tried to tunnel via putty (localhost:65000 (win) -> server:65001) and I've written a little program that creates a listening server (socket) on 127.0.0.1:65000 and sends the information to 192.168.1.2:65001 via 192.168.1.1:65001.
Has anybody an idea how to solve my situation? If so please explain. Maybe this helps others too to handle the adb forwarding function.
hint: The Ports and addresses are only examples. The only fix port number is the listening port on the virtual machine

Related

Can't connect through ADB to device's port

I'm trying to connect to a TV set-top box. After issuing "adb connect my_IP_address" I get this error "No connection could be made because the target machine actively refused it. (10061)". I've tried many basic solutions like the ones from this SO thread but they either don't work or I can't attempt them since they require a USB cable connection and my device dosen't respond to that for some reason.
USB debugging is enabled and I'm sure the device is connected to the same network since I successfully pinged it. Surprisingly I discovered that the 5555 port which is usually used for connecting isn't even open. I got that from using Nmap to check for a particular port. Then I used Nmap to see which ports are open and only got 3:
PORT STATE SERVICE
8008/tcp open http
8009/tcp open ajp13
9000/tcp open cslistener
None of those is suitable for a connection and it looks like there is no available port? What can I do from here?
First, you need to open the 5555 port for communication
Step to open the port
plug your device to the pc
issue command to open the port adb start-server 5555
adb connect my_IP_address:5555

Can't use adb when connected to VPN

My PC and Android TV device are in the same net section,so I can use adb connect the debugging device.Also ,I use adb devices command,it shows device on work.But when My PC and device use the same vpn based on the previous internet,I try to ping the device IP,it worked,then I use adb connect the device,it shows connect,but when input adb devices command , it shows device offline. I'm sure the error can't be caused by adb version,for it can work when disconnect the vpn.who can help me? I'm very appreciate for that.
If your PC and device are on the same LOCAL network, all you need to do is find the local IP address of the device (something like: 192.168.xx.xx). Then type:
adb disconnect
adb connect 192.168.xx.xx.
It'll connect again. Works for me.
The only time it does not work is when the device is the one providing the LOCAL network, e.g., your phone's mobile Hotspot. Using a VPN like this does not work directly. Whenever you use a VPN and try using ADB for a mobile hotspot (and the hotspot device is the one you're trying to connect to), you'll realize that the device goes offline.
This is because when you enter "adb connect <REMOTE_HOST>", your PC tries to route your device IP (REMOTE_HOST) via the VPN network, which will not be accessible since your ISP does not allow inbound connections to your device.
An alternative option, which I use for my device (Phone), is to use a wired connection to my PC via a USB cable. It might work for the Android TV if the proximity b/w TV and your laptop is not a problem.
Another alternative (supposing you're trying to connect a phone/Android TV) is to use another phone or router to create a hotspot. Then connect both your PC and phone/Android TV to the hotspot. Find the phone/Android TV IP address 192.168.xx.xx and enter:
adb connect 192.168.xx.xx.

Connect Android to Computer by Adb Tcp:Ip

i have made an app to share your monitor to your android device by wifi, it works very well.
So i wanted to put as an option to share by usb.
I have found in many websites, the adb tcp connection.
If someone could explain me.
How i can implement such thing.
What i tried so far was:
adb forward tcp:port tcp:port
adb connect ip
No sucess.
Make your app run a server. Run the server on some port e.g. port no. 5749. Send the data thru the server then do adb forward tcp:5749 tcp:5749 and abd connect phoneIP
By the help of these website, I understood how to Connect Tcp via Usb without using Wifi.
So what i wasn't understanding was:
º1 to connect via adb, the android device can only be the server. (otherwise it wasn't working.)
º2 you are going to connect to the localhost (i will explain it better after.) so no need of any wifi ip.
So what i did was:
1º Android: start the server to listen to any connection at PORT (Connect by Usb)
2º PC: use adb, something like:
"shell adb.exe forward tcp:PORT tcp:PORT"
3º PC: try to connect to the server of your android device by the ip which is now "localhost" and your PORT
Then in the code i just redirected the client of the computer as an android device, and handled the server as a normal socket. (Kinda hard to explain myself.)

Use adb forward instead of redir

I have a client and a server app on Android (that uses ZeroC - Ice platform for communication). Server listens on TCP port 10000 and client uses TCP port 5501 (arbitrary port numbers I have chosen).
When I telnet to server and run redir add tcp:5501 tcp:10000 it works smooth.
However, due to my current system setup (using androidx86 binary through a virtual machine), I can no longer telnet to the server. So I was hoping I could use adb forward instead. However, whatever port combination I tried, I couldn't get it to work.
I would really appreciate if someone could shed some light on these:
- Is it possible to telnet to a device replicate or device? I've read on another post on stackoverflow that telnet interface is only available for emulator
- What is the difference between redir and adb forward? How should I use adb forwarding to achieve redir tcp:A:B on server?
Thanks
I've finally managed to get it to work. Several comments
USB connected devices cannot be reached via ethernet. They can be reached via wireless network (assuming they are connected to the same network with the other party)
VirtualBox has its own NAT forwarding. Without port forwarding, under default networking configuration (which is NAT), the virtual device is inaccesible.
My working setup is as follows
A USB-connected device connects to the PC via wireless (Find out your PC's local IP address, which is often something like 192.168.1.x)
I have enabled VirtualBox forwarding for NAT. My option is TCP 10000:10000 (where 10000 is an arbitrary port number. Note that it should be higher than 1024) So when my USB-connected device connects to the PC at port 10000, it is forwarded to the virtual device via VirtualBox's forwarding.
Virtual device listens to TCP port 10000. (I didn't specify host address to make life easier)
If you get a 'NetworkOnMainThread' exception, use
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
Hope this helps someone

Google TV emulator in bridge network mode

I want to connect to my app running in the emulator from another machine on my local network. The ip assigned to emulator is 10.0.2.15 while my host machine has ip 192.168.1.* . Is there any way to run the emulator in bridge mode such that it gets an ip in the range 192.168.1.* ?
The Android Emulator has a virtual router connecting it to the network. You can use the redir command to setup network connections. See this article:
http://developer.android.com/guide/developing/devices/emulator.html#emulatornetworking

Categories

Resources