1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package io.netty.example.sctp;
17
18 import io.netty.bootstrap.Bootstrap;
19 import io.netty.channel.ChannelFuture;
20 import io.netty.channel.ChannelInitializer;
21 import io.netty.channel.EventLoopGroup;
22 import io.netty.channel.MultiThreadIoEventLoopGroup;
23 import io.netty.channel.nio.NioIoHandler;
24 import io.netty.channel.sctp.SctpChannel;
25 import io.netty.channel.sctp.SctpChannelOption;
26 import io.netty.channel.sctp.nio.NioSctpChannel;
27
28
29
30
31
32
33
34
35
36 public final class SctpEchoClient {
37
38 static final String HOST = System.getProperty("host", "127.0.0.1");
39 static final int PORT = Integer.parseInt(System.getProperty("port", "8007"));
40 static final int SIZE = Integer.parseInt(System.getProperty("size", "256"));
41
42 public static void main(String[] args) throws Exception {
43
44 EventLoopGroup group = new MultiThreadIoEventLoopGroup(NioIoHandler.newFactory());
45 try {
46 Bootstrap b = new Bootstrap();
47 b.group(group)
48 .channel(NioSctpChannel.class)
49 .option(SctpChannelOption.SCTP_NODELAY, true)
50 .handler(new ChannelInitializer<SctpChannel>() {
51 @Override
52 public void initChannel(SctpChannel ch) throws Exception {
53 ch.pipeline().addLast(
54
55 new SctpEchoClientHandler());
56 }
57 });
58
59
60 ChannelFuture f = b.connect(HOST, PORT).sync();
61
62
63 f.channel().closeFuture().sync();
64 } finally {
65
66 group.shutdownGracefully();
67 }
68 }
69 }