-
Notifications
You must be signed in to change notification settings - Fork 10.2k
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
How to catch server shutdown? #483
Comments
The server Line 393 in 5254e58
Line 253 in 5254e58
scrcpy/app/src/sys/unix/command.c Line 83 in 5254e58
Anyway, this is what happens if you close |
The code you referred to is for the client (Linux/Windows) side, in C. The server (Android) is written in Java. My question is about Android/Java side. |
The java is executed by |
@rom1v, I can't understand you! The Android side server is started on Android device. Well, probably adb_execute creates a client-side platform process, which is killed in But it does not matter for me anymore :) Meanwhile, I was able to resolve my problem by "self-forking" of com.genymobile.scrcpy.Server when it starts via adb. Now it works as it should, and is closed gracefully on cable disconnect. Now I just need to implement sending a "shutdown" command on client side window close event to the Android part. But it's rather trivial :) |
The adb server (on the device side), when the adb shell 'for i in `seq 1 10`; do echo $i | tee -a /data/local/tmp/test; sleep 1; done' If you unplug the device, or kill the client process, you will see that the server process is also killed. Replug, then:
This can be avoided by catching
What do you do exactly? |
I'm making an Android tablet from my, very small, phone (Unihertz Atom, 2.45", 240x432) and 7" FullHD Windows 10 convertable. For that purpose, I plan to expand scrcpy command line to accept device "screen size" and density. When device side server starts, it saves current screen parameters, and then The main problem was graceful server shutdown at the cable disconnect, to restore phone state. It has been solved. Then I plan to auto-dim phone's backlight, implement on-screen buttons to scrcpy UI window, etc. But I have one more problem to solve: wireless connection! scrcpy can't reverse the protocol with adb over TCP, and the result is awful. I hope it can be done by extracting IP address/port from "device id" in this mode, and connecting via TCP to the server directly... |
Could you explain how, please? |
I pass a parameter to the Java server. It handles this parameter in I can try to commit these changes, just have to cleanup the code, and learn how to push to not my project... |
@Lurker00 Oh I never answered to this message. Thank you for the tip, I keep that in mind (one day I will probably start a new process just to do the cleanup, and use that for the existing |
I'm trying to configure the device (a phone) especially for scrcpy use, and restore device state back when the session ends. I think it is better to do at the server (Java) side, to restore the state even when the connection is broken.
But I've failed to find a point in the server source which is reached or called at the end. The control is not returned to
main()
,DesktopConnection.close()
is never called.I've even tried to create an obect of a class with
finalize()
method, to no avail.Runtime.getRuntime().addShutdownHook()
has no effect either!Does somebody know how to achive the goal: to run some code when the server stops?
The text was updated successfully, but these errors were encountered: