Use adb forward instead of redir - android

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

Related

Android refuses connection via ethernet adapter

I have a SFTP server in my application provided by the Apache SSHD library, which I can access with no problem via the Wifi network connection, but in this project I need to make this server accessible via an ethernet connection.
I have a computer with the ip 169.254.2.2 and I connect it to the Android device via an USB to ethernet adapter (which upon connection becomes the eth0 interface).
Since it is a rooted device that will run the application, I'm using the su process to set the configuration of the network interface with the following commands:
ip addr add 169.254.2.1/24 dev eth0
ip route change 169.254.2.0/24 via 169.254.2.2 dev eth0
//I'm using route change because as soon as I add the ip
//it creates a route table to 169.254.2.0
The settings above seems to be working because both the ethernet icon starts showing on my device and ifconfig command confirms the assigned ip, but when I try to connect to the SFTP server from the computer the connection times out.
So I tried to ping the computer via the device monitoring the network with Wireshark:
Both the request and the reply got delivered fine, but when I try to do the other way around (the computer ping the device) the ping request times out and in Wireshark I get the following:
Android seems to be refusing or ignoring all the requests via the ethernet adapter. Is there a reason to it and/or another way to set my connection so this don't occur?
Additional devices details:
Moto Z Play with Android 7.1.1;
Moto G with Android 5.1 (ethernet icon doesn't show but the connection works the same)

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.)

Android adb forward and own bridge to reach remote server

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

Cannot access localhost from Android device

Emulator can access web service fromlocal host but my real device cannot although I use LAN ip address (192.168.xx.yyy) instead of 10.0.2.2. Of course, my android mobile was recognized by adb and it connected my laptop via usb port.
I already read some similar questions at stackoverflow but still didn't know how to access webservice from a real android mobile. The answer of this question How can I access my localhost from my Android device? my be useful but i don't really understand that answer.
Anyone helps me? Thanks you!
Possibly the web server is listening on the loopback interface but not on the network interface. This means that hits on 127.0.0.1 and localhost will work, but 192.168.xxx.xxx will not (whether from localhost, LAN, or WAN).
To determine which interface the server is listening on, look here for a command to tell you about the listening ports (I used lsof -Pan -i tcp -i udp). Then look for your server process in the list. For the lsof command, if for port 8888 you see something like TCP *:8888 (LISTEN) then your server is listening on all interfaces. But if you instead see something like TCP [::127.0.0.1]:8888 (LISTEN) then you have identified your problem!
The next step to solve your problem is to set up your server's run configuration to listen on all interfaces. I don't know what server you are using, but if you can specify an IP address, then you may want to try 0.0.0.0. Usually you can do this near where it lets you specify the listening port. Thus, if you have a configuration like:
--port 8888
Then you can try:
--port 8888 --address 0.0.0.0
In my opinion, the below point is more important for developer community
I am not a network expert; like me many developers may be there.
change to 0.0.0.0:80 in httpd.conf is very important.
In normal(default) settings, port 8888 throws error in WAMPSERVER (even in Windows Browser). That is why I explained the exact environment where port 8888 throws error.
Specific information about what configuration throws error and what configuration works successfully is more important.
Have you tried using a wifi router which is connected to your LAN? Then you just need to connect to the wifi using your mobile and you should be able to access (192.168.xx.yyy)

Android Emulator (qemu) does not allow certain tcp connections (RST,ACK as answer to SYN)

Although Internet browsing works in the emulator, my app who also runs in the emulator, is unable to connect to a server on the internet on port 5222 via TCP. I'm pretty sure that there is no firewall involved on my router or on my pc, as I can telnet to that ip:port from my pc.
Here is a screenshot of the packettrace taken on the emulator: http://i.stack.imgur.com/sIFFM.png
A packet-trace on the emulated device showed that every SYN packet to that particular port is answered with RST,ACK and the connection is closed by my app with a "connection error".
Why does the emulator block (?) these ports? How can I change it?
The Emulator runs on it's own network, so if you want to communicate through different ports you have to setup forwarding correctly for non-standard ports.
If you want to have external applications connecting to your application running in the emulator you will need to setup your forwarding so that the external application will connect to the port on your development machine and emulator will forward it connection to the 10.0.2.15 which is the emulators address.
See the dev guide for more info:
http://developer.android.com/guide/developing/tools/emulator.html#connecting
Got it. As http://developer.android.com/guide/developing/tools/emulator.html#proxy states, the proxy set in the environment variable http_proxy will be used for all TCP connections.
But my proxy is configured to allow only certain TCP ports.
unset $http_proxy
or use
emulator -http-proxy none
("none" is not a correct proxy, so it will give you an error message. But at least the environment variable is not processed)
PS:
If the -http-proxy command is not supplied, the emulator looks up the http_proxy environment variable and automatically uses any value matching the format described above.
Google, thats crazy. I've set the http_proxy environment variable because I wan't the http(s) traffic to go through that proxy. Not all TCP Connections.

Categories

Resources