Genymobile / scrcpy

Display and control your Android device
Apache License 2.0
108.75k stars 10.47k forks source link

Cannot connect to two devices wirelessly at the same time or specify port #5174

Open 9812ga98sd opened 1 month ago

9812ga98sd commented 1 month ago

Windows 10 scrcpy-win64-v2.6.1 Windows Release from zip file Samsung Xcover Phone Android 13

I want to connect two phones wirelessly.

I use:

scrcpy -s SERIAL_NUMBER_HERE --tcpip (phone1) scrcpy -s SERIAL_NUMBER_HERE --tcpip (Phone2)

This is the result:

INFO: (usb) SERIAL device SM_G715FN INFO: --> (usb) SERIAL device SM_G715FN

INFO: (tcpip) 192.168.1.133:5555 device SM_G715FN INFO: (tcpip) 192.168.1.136:5555 device SM_G715FN

They are both on the same port.

I can connect to the first device using: scrcpy --tcpip=192.168.1.133

When I use:

scrcpy --tcpip=192.168.1.136

... scrcpy 2.6.1 https://github.com/Genymobile/scrcpy INFO: Connecting to 192.168.1.136:5555... failed to authenticate to 192.168.1.136:5555 ERROR: Could not connect to 192.168.1.136:5555 ERROR: Server connection failed ...

Describe the bug

How can I specify a different port? How can I connect and serve two devices?

rom1v commented 1 month ago

failed to authenticate to 192.168.1.136:5555

That does not look related to the fact that there are 2 devices connected.

How can I specify a different port?

There is no need to use a different port (they're not on the same IP).

9812ga98sd commented 1 month ago

failed to authenticate to 192.168.1.136:5555

That does not look related to the fact that there are 2 devices connected.

Ok so why does it not work? What is it related to?

How can I specify a different port?

There is no need to use a different port (they're not on the same IP).

Ok then it should work.

rom1v commented 1 month ago

Ok so why does it not work?

Can you reproduce the problem with your second phone only, without the first one being connected?

9812ga98sd commented 1 month ago

Phone 1 Server: scrcpy -s SERIAL_NUMBER --tcpip

scrcpy 1.25 https://github.com/Genymobile/scrcpy INFO: Switching device XXXXX to TCP/IP... INFO: TCP/IP mode already enabled on port 5555 INFO: Connecting to 192.168.1.155:5555... INFO: Connected to 192.168.1.155:5555 scrcpy-win64 6 Aug 2024\scrcpy-server: 1 file pushed, 0 skipped. 89.9 MB/s (42151 bytes in 0.000s) [server] INFO: Device: samsung SM-G715FN (Android 13) INFO: Renderer: direct3d INFO: Initial texture: 472x1024 INFO: New texture: 1024x472

Client 1: scrcpy --tcpip=192.168.1.155 = ok

Phone 2 Server: scrcpy -s SERIAL_NUMBER --tcpip

scrcpy 1.25 https://github.com/Genymobile/scrcpy INFO: Switching device XXXXX to TCP/IP... INFO: TCP/IP mode already enabled on port 5555 INFO: Connecting to 192.168.1.136:5555... INFO: Connected to 192.168.1.136:5555 scrcpy-win64 6 Aug 2024\scrcpy-server: ...file pushed, 0 skipped. 138.0 MB/s (42151 bytes in 0.000s) [server] INFO: Device: samsung SM-G715FN (Android 13) INFO: Renderer: direct3d INFO: Initial texture: 472x1024

Client 2: scrcpy --tcpip=192.168.1.136

scrcpy 2.6.1 https://github.com/Genymobile/scrcpy INFO: Connecting to 192.168.1.136:5555... failed to authenticate to 192.168.1.136:5555 ERROR: Could not connect to 192.168.1.136:5555 ERROR: Server connection failed

Phone 2 only with phone 1 disconnected from USB

scrcpy-win64>scrcpy --tcpip=192.168.1.136 --max-size 1024 scrcpy 2.6.1 https://github.com/Genymobile/scrcpy INFO: Connecting to 192.168.1.136:5555... failed to authenticate to 192.168.1.136:5555 ERROR: Could not connect to 192.168.1.136:5555 ERROR: Server connection failed

rom1v commented 1 month ago

You can connect from 1 pc to several devices wirelessly (btw, that's what you do and it works).

But you cannot connect 2 PC to 1 device wirelessly (this is a limitation of adb server on the device). You must disconnect the first client to connect the second one. Your logs suggest that it is what you do when it fails (you connect one client with scrcpy 1.25 and another client with scrcpy 2.6.1, so I guess these are two different computers).

9812ga98sd commented 1 month ago

You can connect from 1 pc to several devices wirelessly (btw, that's what you do and it works).

But you cannot connect 2 PC to 1 device wirelessly (this is a limitation of adb server on the device). You must disconnect the first client to connect the second one. Your logs suggest that it is what you do when it fails (you connect one client with scrcpy 1.25 and another client with scrcpy 2.6.1, so I guess these are two different computers).

I am using 2 different computers. I am not trying to connect to 1 device wirelessly from 2 pcs.

PC 1 is connected to the phones via USB. PC 2 is trying to connect wirelessly to the the phones on PC 1

Are you stating that ADB can only serve 1 device wirelessly?

rom1v commented 1 month ago

PC 1 is connected to the phones via USB.

On PC1, since you execute :

scrcpy -s SERIAL_NUMBER --tcpip

Then the devices are also connected wirelessly on PC1. Check adb devices. Or unplug the devices from PC1 while the scrcpy instance launched by this command is still running: mirroring will continue.

9812ga98sd commented 1 month ago
  1. All scrcpy on 2.6.1
  2. All SCRCPY on local drive, no UNC paths.
  3. SCRCPY added to path environment variable in windows.
  4. Add local user as administrator on folder where SCRCPY is installed.

Phone 1 on PC 1

Start scrcpy locally on usb phone 1 using command:

start scrcpy.exe --serial 12345678 --max-size 1024

Displays: scrcpy 2.6.1 https://github.com/Genymobile/scrcpy INFO: ADB device found: INFO: --> (usb) 1234567 device SM_G715FN INFO: (usb) ABCD device SM_G715FN C:\Program Files\scrcpy\scrcpy-server: 1 file pushed, 0 skipped. 110.5 MB/s (71112 bytes in 0.001s) [server] INFO: Device: [samsung] samsung SM-G715FN (Android 13) INFO: Renderer: direct3d INFO: Texture: 1024x472 Works Locally on USB.

Phone 2 on PC 1

Start scrcpy locally on usb phone 2 using command:

start scrcpy.exe --serial ABCD --max-size 1024

Displays:

scrcpy 2.6.1 https://github.com/Genymobile/scrcpy INFO: ADB device found: INFO: --> (usb) ABCD device SM_G715FN INFO: (usb) 1234567 device SM_G715FN C:\Program Files\scrcpy\scrcpy-server: 1 file pushed, 0 skipped. 110.5 MB/s (71112 bytes in 0.001s) [server] INFO: Device: [samsung] samsung SM-G715FN (Android 13) INFO: Renderer: direct3d INFO: Texture: 1024x472

Works Locally on USB.

PC 2

SCRCPY installed on local drive

Phone 1 on PC 2:

scrcpy.exe --serial 192.168.1.155:5555 -max-size 1024

C:\Program Files\scrcpy\Devices>scrcpy.exe --serial 192.168.1.155:5555 --max-size 1024 scrcpy 2.6.1 https://github.com/Genymobile/scrcpy INFO: ADB device found: INFO: --> (tcpip) 192.168.1.155:5555 device SM_G715FN C:\Program Files\scrcpy\scrcpy-server: 1 file pushed, 0 skipped. 68.2 MB/s (71112 bytes in 0.001s) [server] INFO: Device: [samsung] samsung SM-G715FN (Android 13) INFO: Renderer: direct3d INFO: Texture: 1024x472

Phone 2 on PC 2:

scrcpy.exe --serial 192.168.1.124:5555 -max-size 1024

C:\Program Files\scrcpy\Devices>scrcpy.exe --serial 192.168.1.124:5555 --max-size 1024 scrcpy 2.6.1 https://github.com/Genymobile/scrcpy ERROR: Could not find ADB device 192.168.1.124:5555: ERROR: (tcpip) 192.168.1.155:5555 device SM_G715FN ERROR: Server connection failed

rom1v commented 1 month ago

ERROR: Could not find ADB device 192.168.1.124:5555: ERROR: (tcpip) 192.168.1.155:5555 device SM_G715FN

Your device 192.168.1.124 is not connected via adb, only 192.168.1.155 is.

Check adb devices from PC 2.

So make sure it listens over tcp/ip (adb tcpip 5555) then connect to it (adb connect 192.168.1.124) beforehand.

9812ga98sd commented 1 month ago

PC2

C:\Program Files\scrcpy\Devices>adb devices List of devices attached 192.168.1.155:5555 device

PC1 C:\Program Files\scrcpy\Devices>adb tcpip 5555 error: more than one device/emulator

C:\Program Files\scrcpy\Devices>adb connect 192.168.1.124 cannot connect to 192.168.1.124:5555: No connection could be made because the target machine actively refused it. (10061)

Disconnect phone 1 from TCPIP:

adb connect 192.168.1.155 connected to 192.168.1.155:5555

Restart phone 1 in usb not tcpip

adb -s 192.168.1.155:5555 usb restarting in USB mode

Manually disconnect Phone 1 from USB

adb tcpip 5555

error: more than one device/emulator

So PC1 can only serve 1 device wirelessly?

rom1v commented 1 month ago

PC2 C:\Program Files\scrcpy\Devices>adb devices List of devices attached 192.168.1.155:5555 device

So 192.168.1.124 is not connected.

PC1 C:\Program Files\scrcpy\Devices>adb tcpip 5555 error: more than one device/emulator

Like all adb commands, if there are several devices connected, you must specify the one you want to interact with:

adb -s XXXX tcpip 5555

(EDIT: missing 5555)

9812ga98sd commented 1 month ago

PC2 C:\Program Files\scrcpy\Devices>adb devices List of devices attached 192.168.1.155:5555 device

So 192.168.1.124 is not connected.

PC1 C:\Program Files\scrcpy\Devices>adb tcpip 5555 error: more than one device/emulator

Like all adb commands, if there are several devices connected, you must specify the one you want to interact with:

adb -s XXXX tcpip

Which is what I did in the first instance.

C:\Program Files\scrcpy\Devices>adb -s SERIAL_NUMBER tcpip adb.exe: tcpip requires an argument

C:\Program Files\scrcpy\Devices>adb -s 192.168.1.124 tcpip adb.exe: tcpip requires an argument

C:\Program Files\scrcpy\Devices>adb -s 192.168.1.155 tcpip adb.exe: tcpip requires an argument

"Cannot connect to two devices wirelessly at the same time or specify port" The title on this post.

I was asking how to specify the serial number, up or port for 2 devices.

rom1v commented 1 month ago

Sorry, of course, I meant:

adb -s XXXX tcpip 5555

(just add -s XXXX to your command)

9812ga98sd commented 1 month ago

Sorry, of course, I meant:

adb -s XXXX tcpip 5555

(just add -s XXXX to your command)

and that is the command that every one is asking for.

adb -s YOUR_SERIAL_NUMBER_HERE tcpip 5555

9812ga98sd commented 1 month ago

PC 1

C:\Program Files\scrcpy\Devices>adb connect 192.168.1.124 connected to 192.168.1.124:5555

C:\Program Files\scrcpy\Devices>adb connect 192.168.1.155 connected to 192.168.1.155:5555

C:\Program Files\scrcpy\Devices>adb -s SERIAL_NUMERtcpip 5555 restarting in TCP mode port: 5555

C:\Program Files\scrcpy\Devices>adb -s SERIAL_NUMBER tcpip 5555 restarting in TCP mode port: 5555

PC2

C:\Program Files\scrcpy\Devices>scrcpy.exe --serial 192.168.1.155:5555 --max-size 1024 scrcpy 2.6.1 https://github.com/Genymobile/scrcpy ERROR: Could not find any ADB device ERROR: Server connection failed

C:\Program Files\scrcpy\Devices>scrcpy.exe --serial 192.168.1.124:5555 --max-size 1024 scrcpy 2.6.1 https://github.com/Genymobile/scrcpy ERROR: Could not find any ADB device ERROR: Server connection failed

rom1v commented 1 month ago

IIUC what you are trying to do, you want to connect both devices via USB on PC1, and via Wifi on PC2.

Disconnect everything, reboot your devices, restart adb (adb kill-server) on both machines.

Then on PC1, connect both devices over USB, and make them listen over tcpip:

adb -s SERIAL_NUMBER_DEVICE_1 tcpip 5555
adb -s SERIAL_NUMBER_DEVICE_2 tcpip 5555

Then on PC2, execute:

adb connect IP_DEVICE_1:5555
adb connect IP_DEVICE_2:5555

and adb devices to check that both devices are connected.

That's it.

9812ga98sd commented 1 month ago
  1. adb kill-server on both machines
  2. Both phones restarted.
  3. Adb devices to check which are connected.

PC 1:

adb devices

List of devices attached SERIAL1 device SERIAL2 device

MAKE 2 CONSOLE WINDOWS

Console 1 adb -s SERIAL1 tcpip 5555 restarting in TCP mode port: 5555

Console 2 adb -s SERIAL2 tcpip 5555 restarting in TCP mode port: 5555

PC2:

C:\Program Files\scrcpy\Devices>adb kill-server

C:\Program Files\scrcpy\Devices>adb devices List of devices attached 192.168.1.124:5555 device 192.168.1.155:5555 device

Console window 1

C:\Program Files\scrcpy\Devices>adb connect 192.168.1.124:5555 connected to 192.168.1.124:5555

scrcpy.exe --serial 192.168.1.124:5555 --max-size 1024

Console window 2

C:\Program Files\scrcpy\Devices>adb connect 192.168.1.124:5555 connected to 192.168.1.124:5555

scrcpy.exe --serial 192.168.1.155:5555 --max-size 1024

It works.

Some suggestions.

  1. The terminology is very confusing. ADB using -serial number when its an IP address. It seems unreliable.
  2. Each device needs to be started in TCPIP mode but can use the same port, but also each device needs to be connected to as well.

A few minutes later i couldnt connect to the phone 1 on usb using scrcpy.

rom1v commented 1 month ago

The terminology is very confusing. ADB using -serial number when its an IP address. It seems unreliable.

adb is from Android, I have no control over it. I use the same -s behavior for consistency in scrcpy.

Each device needs to be started in TCPIP mode but can use the same port

That's not a problem: each listens on the same port locally (on the device), and they are exposed via a different ip, so ip:port is different.

also each device needs to be connected to as well.

Not sure to understand.

From PC2, if you want to connect to two devices, you needs to adb connect both devices… how would you do differently?

9812ga98sd commented 1 month ago

Some points. Windows 10: On PC1 If you use the same console window to issue: adb -s SERIAL1 tcpip 5555 adb -s SERIAL2 tcpip 5555

one of them fails and no "restarting in TCP mode port: 5555" is issued.

If you use 2 separate console windows, each window works and you get the correct messages.

On PC2 same issue, use 2 console windows and it works.

I am trying to automate it with batch files on PC 1 but the adb commands don't seem to run.

adb -s PHONE_SERIAL tcpip 5555 adb connect 192.168.1.124:5555

doesnt seem to run when put into a batch file.

On PC 2

"scrcpy.exe --serial 192.168.1.124:5555 --max-size 1024" can be put into a .bat (batch) file and it runs fine.

also each device needs to be connected to as well.

I mean each device needs adb -s PHONE_SERIAL tcpip 5555 and an adb connect 192.168.1.124:5555 to be run on it in a console window, not just adb -s PHONE_SERIAL tcpip 5555