12
|
1 package alice.daemon;
|
|
2
|
|
3 import java.io.IOException;
|
|
4 import java.net.InetAddress;
|
|
5 import java.net.InetSocketAddress;
|
|
6 import java.net.ServerSocket;
|
|
7 import java.nio.channels.ServerSocketChannel;
|
|
8
|
|
9 public class AliceDaemon {
|
|
10
|
|
11 private Config conf;
|
|
12 private AcceptThread acceptThread;
|
|
13
|
|
14 public AliceDaemon(String[] args) {
|
|
15 this.conf = new Config(args);
|
|
16 }
|
|
17
|
|
18 public void listen() {
|
|
19 try {
|
|
20 ServerSocketChannel ssChannel = ServerSocketChannel.open();
|
|
21 ServerSocket ss = ssChannel.socket();
|
|
22 ss.setReuseAddress(true);
|
|
23 ss.bind(new InetSocketAddress(InetAddress.getLocalHost(), conf.port));
|
|
24 acceptThread = new AcceptThread(ss, "ACCEPT" + conf.port);
|
|
25 acceptThread.start();
|
|
26
|
|
27 } catch (IOException e) {
|
|
28 e.printStackTrace();
|
|
29 }
|
|
30
|
|
31 }
|
|
32 }
|