Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Help Needed] scrcpy-server on Android hangs #2094

Closed
2 tasks done
r-luo opened this issue Feb 6, 2021 · 4 comments
Closed
2 tasks done

[Help Needed] scrcpy-server on Android hangs #2094

r-luo opened this issue Feb 6, 2021 · 4 comments

Comments

@r-luo
Copy link

r-luo commented Feb 6, 2021

  • I have read the FAQ.
  • I have searched in existing issues.

Environment

  • OS: Ubuntu 20.04
  • scrcpy version: 1.17
  • installation method: linuxbrew
  • device model: Huawei Mate 20 Pro (connected to adb wirelessly via atx-agent)
  • Android version: 10

Hi,

I'm trying to stream my phone screen into Python. I found this script https://gist.github.com/Allong12/a752decf49e6c789c2425e35028137a5 from way back in 2019 and tried to modify it. However, the server would freeze whenever I try to receive anything with sock.recv in Python.

Things done in Bash (Not even sure if my arguments for scrcpy-server even make sense..):

wget https://github.com/Genymobile/scrcpy/releases/download/v1.17/scrcpy-server-v1.17
cp scrcpy-server-v1.17 scrcpy-server.jar
adb -s 192.168.50.229:5555 push scrcpy-server.jar /data/local/tmp/
adb -s 192.168.50.229:5555 shell CLASSPATH=/data/local/tmp/scrcpy-server.jar app_process / com.genymobile.scrcpy.Server 1.17 info 960 1073741824 60 -1 true - false true 0 false false - -

The above would hang at

[server] INFO: Device: HUAWEI LYA-L0C (Android 10)

And I had to open another shell process to run

adb -s 192.168.50.229:5555 forward tcp:8080 localabstract:scrcpy

Now in Python:

import socket
import struct
import sys
import subprocess
import io

IP = '127.0.0.1'
PORT = 8080

print("Connecting")
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((IP, PORT))


DUMMYBYTE = sock.recv(1)
if not len(DUMMYBYTE):
    print("Failed to connect!")
    exit()
else:
    print("Connected!")

It'll print "Connected!" as a dummy byte is received. However, any subsequent call to sock.recv would hang in python:

deviceName = sock.recv(64)
print("Device Name:",deviceName.decode("utf-8"))

^ this hangs.

I'm wondering if anyone can help me understand what's going on / help me make it work... Thanks in advance!

@r-luo r-luo changed the title [Help Needed] Cannot socket.recv in Python from to scrcpy-server [Help Needed] Cannot socket.recv in Python from scrcpy-server Feb 6, 2021
@r-luo r-luo changed the title [Help Needed] Cannot socket.recv in Python from scrcpy-server [Help Needed] scrcpy-server on Android hangs Feb 6, 2021
@rom1v
Copy link
Collaborator

rom1v commented Feb 6, 2021

Now, you have to connect 2 sockets (1 for video, 1 for control in both directions): ec71a3f

Refs #129 (comment)

@r-luo
Copy link
Author

r-luo commented Feb 7, 2021

@rom1v Thanks so much for your response!

Unfortunately I'm pretty illiterate in networking so I'm not sure what I should do to make it work after reading the links you provided... Would you mind offering some possible changes I can make to the code above in order to receive screenshots from scrcpy-server started on the phone?

@Bujuhu
Copy link

Bujuhu commented Feb 8, 2021

Hi!

This is probably what you are looking for.

Or you could use use the class provided by py-android-viewer directly if you don't want program the networking bit yourself

@r-luo
Copy link
Author

r-luo commented Feb 9, 2021

Hi!

This is probably what you are looking for.

Or you could use use the class provided by py-android-viewer directly if you don't want program the networking bit yourself

OMG it works perfectly. Thank you so much!!! You just made my day 😁

@r-luo r-luo closed this as completed Feb 9, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants