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.)
Related
I'm trying to make a tool that connects to your android phone wirelessly with the connect command.
I know the command and how to set up the ports, the problem is that you have to enter your ip manually. If i want it to be a tool, it should automatically connect to the right ip for the user's phone.
I've tried using localhost to connect
adb connect localhost:5555
But that does not work. If this is possible, please write a comment!
I'm sorry if i didnt explain it properly. English is not my main language.
You're not entering the command correctly. You should be connecting to the device's ip. adb connect [deviceIP]:5555.
I am programming an Android app which connects to a TCP server running on my computer using sockets. This works perfectly fine as long as both my computer and my smartphone are connected to the Wi-Fi of my router.
I want it to also work when my computer and my phone are not connected to the Wi-Fi. Therefore I configured a Wi-Fi hotspot using hosted network on my computer. My smartphone recognizes the Wi-Fi and is able to connect to it. But now my app can't connect to the server running on my PC although I changed the code to the new IP that I got by using ipconfig on my PC.
I downloaded an app named "Fing" from the Google play store. The app shows all devices in a network. It does show my computer under the right IP address. I don't understand why my app can't connect to the server running on the PC.
On the one hand, I don't think that the problem is in the app's code, because it works on the router's Wi-Fi network. On the other hand, I doesn't seem to be a setup mistake either, because Fing is detecting my PC.
Do you have any ideas what the problem might be, or any other solution for my needs?
I actually wrote the TCP server myself using c#. I configured the Server to listen to all of my computers networkinterfaces usingIPAdress.IPv6Any. I also did configure it as dual mode socket so it can accept ipv4 and ipv6 connections. I will post the code when i am back home. So the TCP server also looks ok to me.
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
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
I'm new to Android development, I'm developing FTP client application for Android.
I'm using FTP in active mode I running list command in active mode for which server has to open data port for sending list response. I'm testing my application in Eclipse emulator.
When I run list command it will give following error, failed to establish a connection.
I have some question regarding this
Can we open data port in the emulator?
if yes then it will open ports from development machine or in the emulator itself.
also kindly tell how to fix this problem any help and suggestion is greatly appreciated.
Usually android emulator has different network with its own ip address and so on. For communicating with the server, when the server connects to development pc and issue the command, you need to redirect that to the port of the emulator.
Example:
Server is connecting to emulator on port 1234
Redirect the development machine port 1234 to emulator with the following commands
in the command prompt
C:> telnet localhost
Ex: telnet localhost 5554
(Will be logged in to the emulator)
->redir add <tcp/udp>:hostport:emulatorport
Ex: redir add udp:1234:1234
->quit
For Ref: https://developer.android.com/studio/run/emulator-networking
Regards,
SSuman185