1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty.example.udt.echo.message;
17
18 import io.netty.bootstrap.Bootstrap;
19 import io.netty.channel.ChannelFuture;
20 import io.netty.channel.ChannelInitializer;
21 import io.netty.channel.nio.NioEventLoopGroup;
22 import io.netty.channel.udt.UdtChannel;
23 import io.netty.channel.udt.nio.NioUdtProvider;
24 import io.netty.handler.logging.LogLevel;
25 import io.netty.handler.logging.LoggingHandler;
26 import io.netty.util.concurrent.DefaultThreadFactory;
27
28 import java.util.concurrent.ThreadFactory;
29 import java.util.logging.Logger;
30
31
32
33
34
35
36
37
38
39 public final class MsgEchoClient {
40
41 private static final Logger log = Logger.getLogger(MsgEchoClient.class.getName());
42
43 static final String HOST = System.getProperty("host", "127.0.0.1");
44 static final int PORT = Integer.parseInt(System.getProperty("port", "8007"));
45 static final int SIZE = Integer.parseInt(System.getProperty("size", "256"));
46
47 public static void main(String[] args) throws Exception {
48
49
50 final ThreadFactory connectFactory = new DefaultThreadFactory("connect");
51 final NioEventLoopGroup connectGroup = new NioEventLoopGroup(1,
52 connectFactory, NioUdtProvider.MESSAGE_PROVIDER);
53 try {
54 final Bootstrap boot = new Bootstrap();
55 boot.group(connectGroup)
56 .channelFactory(NioUdtProvider.MESSAGE_CONNECTOR)
57 .handler(new ChannelInitializer<UdtChannel>() {
58 @Override
59 public void initChannel(final UdtChannel ch)
60 throws Exception {
61 ch.pipeline().addLast(
62 new LoggingHandler(LogLevel.INFO),
63 new MsgEchoClientHandler());
64 }
65 });
66
67 final ChannelFuture f = boot.connect(HOST, PORT).sync();
68
69 f.channel().closeFuture().sync();
70 } finally {
71
72 connectGroup.shutdownGracefully();
73 }
74 }
75 }