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.buffer.ByteBuf;
19 import io.netty.buffer.Unpooled;
20 import io.netty.channel.ChannelHandlerContext;
21 import io.netty.channel.ChannelInboundHandlerAdapter;
22 import io.netty.channel.sctp.SctpMessage;
23
24
25
26
27
28
29 public class SctpEchoClientHandler extends ChannelInboundHandlerAdapter {
30
31 private final ByteBuf firstMessage;
32
33
34
35
36 public SctpEchoClientHandler() {
37 firstMessage = Unpooled.buffer(SctpEchoClient.SIZE);
38 for (int i = 0; i < firstMessage.capacity(); i++) {
39 firstMessage.writeByte((byte) i);
40 }
41 }
42
43 @Override
44 public void channelActive(ChannelHandlerContext ctx) {
45 ctx.writeAndFlush(new SctpMessage(0, 0, firstMessage));
46 }
47
48 @Override
49 public void channelRead(ChannelHandlerContext ctx, Object msg) {
50 ctx.write(msg);
51 }
52
53 @Override
54 public void channelReadComplete(ChannelHandlerContext ctx) {
55 ctx.flush();
56 }
57
58 @Override
59 public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {
60
61 cause.printStackTrace();
62 ctx.close();
63 }
64 }