The problem is solved. It's due to the filepath of adb.
I'm trying to use adb forward with C#.
If I use the adb forward command directly in cmd, it works fine. And if I use the cmd command like "start explorer" with C#, it works fine too. However, it cannot be accessed using adb forward in C#. I've tried to turn the firewall off but it doesn't make sense.
IPAddress ip = IPAddress.Parse("127.0.0.1");
Process p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.ErrorDialog = false;
p.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
p.Start();
p.StandardInput.WriteLine("adb forward tcp:8000 tcp:9000");
try
{
clientSocket.Connect(new IPEndPoint(ip, 8000));
Console.WriteLine("1");
}
catch
{
Console.WriteLine("2");
return;
}
The exception message
Exception thrown: 'System.Net.Sockets.SocketException' in System.dll
Exception caught: System.Net.Sockets.SocketException (0x80004005): No connection could be made because the target machine actively refused it 127.0.0.1:8000
User contributions licensed under CC BY-SA 3.0