-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBridge.java
More file actions
84 lines (72 loc) · 1.67 KB
/
Bridge.java
File metadata and controls
84 lines (72 loc) · 1.67 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
/*
*
* Developed by 1Ridav.
* Published under GNU General Public Licence 3.0
*
* Visit our web site http://computercraft.ru
*
*
*
* */
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Date;
public class Bridge {
public static void main(String[] args) throws IOException {
if(args.length > 0){
Data.PORT = Integer.parseInt(args[0]);
if(args.length > 1){
Data.WEB_PORT = Integer.parseInt(args[1]);
}
}
new Bridge();
}
public Bridge() {
startServer();
}
private void startServer() {
ServerSocket ss = null;
Socket socket = null;
User u = null;
try {
ss = new ServerSocket(Data.PORT);
System.out.println("Server Started on port " + Data.PORT);
new Admin();
new Web();
while (Data.acceptConnections) {
try{
socket = ss.accept();
u = new User(socket);
u.self = u;
Data.addUnknownUser(u);// add to pool of unpaired
// connections
} catch (IOException e) {
socket.close();
}
}
} catch (IOException e1) {
}finally{
try {
ss.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
public static synchronized boolean findPair(User self){
for(User u : Data.unpairedUsers){
if(u.KEY.equals(self.KEY)){
//if(u.isAndroid != self.isAndroid){ //CONNECT ONLY ANDROID TO OC
if(u != self){ //CONNECT ANY DEVICES TO EACH OTHER
u.onPairFound(self);
self.onPairFound(u);
Data.moveToPaired(u);
Data.moveToPaired(self);
return true;
}
}
}
return false;
}
}