1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.jboss.netty.example.telnet;
17
18 import org.jboss.netty.bootstrap.ServerBootstrap;
19 import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;
20 import org.jboss.netty.handler.ssl.SslContext;
21 import org.jboss.netty.handler.ssl.util.SelfSignedCertificate;
22
23 import java.net.InetSocketAddress;
24 import java.util.concurrent.Executors;
25
26
27
28
29 public final class TelnetServer {
30
31 static final boolean SSL = System.getProperty("ssl") != null;
32 static final int PORT = Integer.parseInt(System.getProperty("port", SSL? "8992" : "8023"));
33
34 public static void main(String[] args) throws Exception {
35
36 final SslContext sslCtx;
37 if (SSL) {
38 SelfSignedCertificate ssc = new SelfSignedCertificate();
39 sslCtx = SslContext.newServerContext(ssc.certificate(), ssc.privateKey());
40 } else {
41 sslCtx = null;
42 }
43
44
45 ServerBootstrap bootstrap = new ServerBootstrap(
46 new NioServerSocketChannelFactory(
47 Executors.newCachedThreadPool(),
48 Executors.newCachedThreadPool()));
49
50
51 bootstrap.setPipelineFactory(new TelnetServerPipelineFactory(sslCtx));
52
53
54 bootstrap.bind(new InetSocketAddress(PORT));
55 }
56 }