Skip to content

Commit

Permalink
Configurable web-socket server's port number
Browse files Browse the repository at this point in the history
  • Loading branch information
drauggres committed May 7, 2020
1 parent e3ac983 commit 739c277
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 9 deletions.
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 @@ -19,6 +19,7 @@ public class Options {
private boolean control;
private int displayId;
private int serverType = TYPE_LOCAL_SOCKET;
private int portNumber = 8886;

public int getMaxSize() {
return maxSize;
Expand Down Expand Up @@ -110,6 +111,14 @@ public void setServerType(int type) {
}
}

public void setPortNumber(int portNumber) {
this.portNumber = portNumber;
}

public int getPortNumber() {
return this.portNumber;
}

@Override
public String toString() {
return "Options{"
Expand Down
14 changes: 10 additions & 4 deletions server/src/main/java/com/genymobile/scrcpy/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,18 @@ private static void parseArguments(Options options, VideoSettings videoSettings,
int displayId = Integer.parseInt(args[9]);
options.setDisplayId(displayId);

if (args.length > 11) {
throw new IllegalArgumentException("Expecting no more then 10 parameters");
if (args.length > 12) {
throw new IllegalArgumentException("Expecting no more then 11 parameters");
}

if (args.length == 11 && args[10].toLowerCase().equals("web")) {
options.setServerType(Options.TYPE_WEB_SOCKET);
if (args.length > 10) {
if (args[10].toLowerCase().equals("web")) {
options.setServerType(Options.TYPE_WEB_SOCKET);
}
}
if (args.length > 11) {
int portNumber = Integer.parseInt(args[11]);
options.setPortNumber(portNumber);
}
}

Expand Down
6 changes: 2 additions & 4 deletions server/src/main/java/com/genymobile/scrcpy/WSServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,10 @@ public interface EventsHandler {
void onStart();
}

final static private int DEFAULT_PORT_NUMBER = 8886; // 843 flash policy port

private EventsHandler eventsHandler;

public WSServer(EventsHandler handler) {
super(new InetSocketAddress(DEFAULT_PORT_NUMBER));
public WSServer(EventsHandler handler, int portNumber) {
super(new InetSocketAddress(portNumber));
eventsHandler = handler;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class WebSocketConnection extends Connection implements WSServer.EventsHa

public WebSocketConnection(Options options, VideoSettings videoSettings) {
super(options, videoSettings);
wsServer = new WSServer(this);
wsServer = new WSServer(this, options.getPortNumber());
wsServer.setReuseAddr(true);
wsServer.run();
}
Expand Down

0 comments on commit 739c277

Please sign in to comment.