1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty.example.qotm;
17
18 import io.netty.bootstrap.Bootstrap;
19 import io.netty.channel.ChannelOption;
20 import io.netty.channel.EventLoopGroup;
21 import io.netty.channel.MultiThreadIoEventLoopGroup;
22 import io.netty.channel.nio.NioIoHandler;
23 import io.netty.channel.socket.nio.NioDatagramChannel;
24
25
26
27
28
29
30
31 public final class QuoteOfTheMomentServer {
32
33 private static final int PORT = Integer.parseInt(System.getProperty("port", "7686"));
34
35 public static void main(String[] args) throws Exception {
36 EventLoopGroup group = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory());
37 try {
38 Bootstrap b = new Bootstrap();
39 b.group(group)
40 .channel(NioDatagramChannel.class)
41 .option(ChannelOption.SO_BROADCAST, true)
42 .handler(new QuoteOfTheMomentServerHandler());
43
44 b.bind(PORT).sync().channel().closeFuture().await();
45 } finally {
46 group.shutdownGracefully();
47 }
48 }
49 }