1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.jboss.netty.example.securechat;
17
18 import java.net.InetSocketAddress;
19 import java.util.concurrent.Executors;
20
21 import org.jboss.netty.bootstrap.ServerBootstrap;
22 import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
23 import org.jboss.netty.example.telnet.TelnetServer;
24
25
26
27
28 public class SecureChatServer {
29
30 private final int port;
31
32 public SecureChatServer(int port) {
33 this.port = port;
34 }
35
36 public void run() {
37
38 ServerBootstrap bootstrap = new ServerBootstrap(
39 new NioServerSocketChannelFactory(
40 Executors.newCachedThreadPool(),
41 Executors.newCachedThreadPool()));
42
43
44 bootstrap.setPipelineFactory(new SecureChatServerPipelineFactory());
45
46
47 bootstrap.bind(new InetSocketAddress(port));
48 }
49
50 public static void main(String[] args) throws Exception {
51 int port;
52 if (args.length > 0) {
53 port = Integer.parseInt(args[0]);
54 } else {
55 port = 8443;
56 }
57 new SecureChatServer(port).run();
58 }
59 }