scrcpy icon indicating copy to clipboard operation
scrcpy copied to clipboard

How does the client obtain data from the scrcpy service started on the mobile phone?

Open HitomiHong opened this issue 1 year ago • 1 comments

  • [ yes ] I have read the FAQ.
  • [ yes ] I have searched in existing issues.

Environment

  • OS: Windows
  • scrcpy version: 1.18
  • installation method: [e.g. manual build, apt, snap, brew, Windows release...]
  • device model: Oppo Reno ACE
  • Android version: 10

Describe the bug

Hello, I pushed the scrcpy server to the Android phone and started the service.

It looks like the service is indeed started.

[server] INFO: Device: OPPO PCLM10 (Android 10)

I wrote a simple client to get the data pushed by the service, but I can only get dummy byte.

data == >  b'\x00'

The following is the client code I wrote. I wonder if you can help me find out why I can’t get the subsequent data. These three methods are called from top to bottom.


def client_socket():
    # client socket
    client: socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

    server_addr = ('127.0.0.1', 27183)
    client.connect(server_addr)

    data = client.recv(1)
    if not len(data):
        raise IOError('no data')
    print('data == > ', data)

    data = client.recv(64).decode("utf-8").rstrip("\x00")
    print('data == > ', data)

    data = client.recv(4).decode("utf-8").rstrip("\x00")
    print('data == > ', data)

In addition, this is my process of pushing the scrcpy service

def push_scrcpy():
    """
    push scrcpy.jar
    """
    # push file to /data/local/tmp
    cmd = r'adb push E:\MySoftware\scrcpy-server.jar /data/local/tmp/scrcpy-server.jar'
    process = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    stdout, stderr = process.communicate()

    if process.returncode == 0:
        print('push successfully')

    else:
        print("push error")
        print("error:", stderr.decode())

def forward_scrcpy():
    """
    forward
    """
    cmd = 'adb forward tcp:27183 localabstract:scrcpy'
    try:
        output = subprocess.call(cmd)
        # output = output.decode('utf-8')
        print(output)
    except subprocess.CalledProcessError as e:
        print('forward error:', e)

def start_scrcpy_android():
    """
    start scrcpy server
    """
    cmd = ('adb shell CLASSPATH=/data/local/tmp/scrcpy-server.jar app_process / com.genymobile.scrcpy.Server 1.18 info '
           '1600 20000000 0 -1 true - false true 0 false false - - false')

    process = subprocess.Popen(cmd)
    process.wait()
    print('scrcpy-server end')

Looking forward to your answer very much

HitomiHong avatar Feb 05 '24 09:02 HitomiHong

Please read: https://github.com/Genymobile/scrcpy/blob/master/doc/develop.md#protocol

rom1v avatar Feb 05 '24 09:02 rom1v