diff --git a/server/src/main/java/com/genymobile/scrcpy/DesktopConnection.java b/server/src/main/java/com/genymobile/scrcpy/DesktopConnection.java index ca20c1d8..78728d81 100644 --- a/server/src/main/java/com/genymobile/scrcpy/DesktopConnection.java +++ b/server/src/main/java/com/genymobile/scrcpy/DesktopConnection.java @@ -46,15 +46,17 @@ public final class DesktopConnection implements Closeable { return localSocket; } - public static DesktopConnection open(boolean tunnelForward, boolean control) throws IOException { + public static DesktopConnection open(boolean tunnelForward, boolean control, boolean sendDummyByte) throws IOException { LocalSocket videoSocket; LocalSocket controlSocket = null; if (tunnelForward) { LocalServerSocket localServerSocket = new LocalServerSocket(SOCKET_NAME); try { videoSocket = localServerSocket.accept(); - // send one byte so the client may read() to detect a connection error - videoSocket.getOutputStream().write(0); + if (sendDummyByte) { + // send one byte so the client may read() to detect a connection error + videoSocket.getOutputStream().write(0); + } if (control) { try { controlSocket = localServerSocket.accept(); diff --git a/server/src/main/java/com/genymobile/scrcpy/Options.java b/server/src/main/java/com/genymobile/scrcpy/Options.java index 9210b318..92cf1e7a 100644 --- a/server/src/main/java/com/genymobile/scrcpy/Options.java +++ b/server/src/main/java/com/genymobile/scrcpy/Options.java @@ -25,6 +25,7 @@ public class Options { // Options not used by the scrcpy client, but useful to use scrcpy-server directly private boolean sendDeviceMeta = true; // send device name and size private boolean sendFrameMeta = true; // send PTS so that the client may record properly + private boolean sendDummyByte = true; // write a byte on start to detect connection issues public Ln.Level getLogLevel() { return logLevel; @@ -169,4 +170,12 @@ public class Options { public void setSendFrameMeta(boolean sendFrameMeta) { this.sendFrameMeta = sendFrameMeta; } + + public boolean getSendDummyByte() { + return sendDummyByte; + } + + public void setSendDummyByte(boolean sendDummyByte) { + this.sendDummyByte = sendDummyByte; + } } diff --git a/server/src/main/java/com/genymobile/scrcpy/Server.java b/server/src/main/java/com/genymobile/scrcpy/Server.java index 20fd1c1b..d9c22771 100644 --- a/server/src/main/java/com/genymobile/scrcpy/Server.java +++ b/server/src/main/java/com/genymobile/scrcpy/Server.java @@ -66,8 +66,9 @@ public final class Server { boolean tunnelForward = options.isTunnelForward(); boolean control = options.getControl(); + boolean sendDummyByte = options.getSendDummyByte(); - try (DesktopConnection connection = DesktopConnection.open(tunnelForward, control)) { + try (DesktopConnection connection = DesktopConnection.open(tunnelForward, control, sendDummyByte)) { if (options.getSendDeviceMeta()) { Size videoSize = device.getScreenInfo().getVideoSize(); connection.sendDeviceMeta(Device.getDeviceName(), videoSize.getWidth(), videoSize.getHeight()); @@ -248,6 +249,10 @@ public final class Server { boolean sendFrameMeta = Boolean.parseBoolean(value); options.setSendFrameMeta(sendFrameMeta); break; + case "send_dummy_byte": + boolean sendDummyByte = Boolean.parseBoolean(value); + options.setSendDummyByte(sendDummyByte); + break; default: Ln.w("Unknown server option: " + key); break;