Skip to content

Commit

Permalink
Add server option send_dummy_byte
Browse files Browse the repository at this point in the history
If set to false, no dummy byte is written to detect a connection error.

PR #2971 <#2971>
  • Loading branch information
rom1v committed Jan 26, 2022
1 parent 3ba32c2 commit 45a5e56
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,17 @@ private static LocalSocket connect(String abstractName) throws IOException {
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();
Expand Down
9 changes: 9 additions & 0 deletions server/src/main/java/com/genymobile/scrcpy/Options.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -169,4 +170,12 @@ public boolean getSendFrameMeta() {
public void setSendFrameMeta(boolean sendFrameMeta) {
this.sendFrameMeta = sendFrameMeta;
}

public boolean getSendDummyByte() {
return sendDummyByte;
}

public void setSendDummyByte(boolean sendDummyByte) {
this.sendDummyByte = sendDummyByte;
}
}
7 changes: 6 additions & 1 deletion server/src/main/java/com/genymobile/scrcpy/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,9 @@ private static void scrcpy(Options options) throws IOException {

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());
Expand Down Expand Up @@ -248,6 +249,10 @@ private static Options createOptions(String... args) {
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;
Expand Down

0 comments on commit 45a5e56

Please sign in to comment.