forked from imharryzhu/AndroidControl
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
90 lines (81 loc) · 2.87 KB
/
Main.java
File metadata and controls
90 lines (81 loc) · 2.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package com.yeetor;
import com.neovisionaries.ws.client.WebSocketException;
import com.yeetor.androidcontrol.client.RemoteClient;
import com.yeetor.androidcontrol.server.LocalServer;
import com.yeetor.androidcontrol.server.RemoteServer;
import java.security.InvalidParameterException;
/**
* Created by harry on 2017/4/15.
*/
public class Main {
/**
* [server port]
* [client ip port serialNumber]
* [client ip port]
*/
public static void main(String[] args) {
try {
Config config = new Config(args);
if (config.isClient) {
new RemoteClient(config.ip, config.port, config.key, config.serialNumber);
} else {
if (config.isLocal) {
new LocalServer(config.port).start();
} else {
new RemoteServer(config.port).start();
}
}
} catch (InvalidParameterException ex) {
System.out.println("localserver <port>: 启动本地服务器(p2p)\n remoteserver <port> 启动服务器 \nremoteclient <ip> <port> <key> [serialNumber] 启动客户端");
System.exit(0);
} catch (WebSocketException|InterruptedException e) {
System.out.println("启动服务器失败: " + e.getMessage());
System.exit(0);
} catch (Exception e) {
e.printStackTrace();
System.exit(0);
}
}
static class Config {
boolean isLocal = true;
boolean isClient = false;
String ip = "";
int port = 6655;
String serialNumber = "";
String key = "";
Config(String[] args) throws InvalidParameterException {
if (args.length > 0) {
if ("localserver".equals(args[0])) {
isLocal = true;
isClient = false;
} else if ("remoteserver".equals(args[0])) {
isLocal = false;
isClient = false;
} else {
isLocal = true;
isClient = true;
}
}
if (isClient) {
if (args.length == 4) {
ip = args[1];
port = Integer.parseInt(args[2]);
key = args[3];
} else if (args.length == 5) {
ip = args[1];
port = Integer.parseInt(args[2]);
key = args[3];
serialNumber = args[4];
} else {
throw new InvalidParameterException("参数不正确");
}
} else {
if (args.length == 2) {
port = Integer.parseInt(args[1]);
} else {
throw new InvalidParameterException("参数不正确");
}
}
}
}
}