-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathServer.java
More file actions
71 lines (57 loc) · 1.54 KB
/
Copy pathServer.java
File metadata and controls
71 lines (57 loc) · 1.54 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
package net;
import data.Game;
import ui.UI;
import javax.swing.*;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
public class Server {
Thread acceptThread;
ServerSocket serverSocket;
public int port = 7103;
Socket socket;
JFrame frame;
public static final int TAG = 0;
public Server(Integer port, JFrame frame) throws IOException {
this.frame = frame;
if (port != null) {
this.port = port;
}
Game.isServer = true;
initServerSocket();
createRoom();
}
void createRoom() {
Thread thread = new Thread() {
@Override
public void run() {
try {
socket = serverSocket.accept();
} catch (IOException e) {
e.printStackTrace();
}
}
};
thread.start();
JOptionPane.showMessageDialog(UI.frame, "된덤鯤소속흙");
while (socket == null) {
try {
Thread.sleep(1000);
} catch (InterruptedException ignored) {
}
}
if (socket != null) {
JOptionPane.showMessageDialog(UI.frame, "鯤소속흙냥묘");
}
frame.setVisible(false);
new NetJudge(socket, TAG);
}
private void initServerSocket() throws IOException {
serverSocket = new ServerSocket(port);
}
public void closeGetSocket() {
if (acceptThread != null) {
acceptThread.interrupt();
}
}
}