1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.jboss.netty.example.discard;
17
18 import java.net.InetSocketAddress;
19 import java.util.concurrent.Executors;
20
21 import org.jboss.netty.bootstrap.ClientBootstrap;
22 import org.jboss.netty.channel.ChannelFuture;
23 import org.jboss.netty.channel.ChannelPipeline;
24 import org.jboss.netty.channel.ChannelPipelineFactory;
25 import org.jboss.netty.channel.Channels;
26 import org.jboss.netty.channel.socket.nio.NioClientSocketChannelFactory;
27
28
29
30
31
32
33
34
35
36 public class DiscardClient {
37
38 public static void main(String[] args) throws Exception {
39
40 if (args.length < 2 || args.length > 3) {
41 System.err.println(
42 "Usage: " + DiscardClient.class.getSimpleName() +
43 " <host> <port> [<first message size>]");
44 return;
45 }
46
47
48 final String host = args[0];
49 final int port = Integer.parseInt(args[1]);
50 final int firstMessageSize;
51 if (args.length == 3) {
52 firstMessageSize = Integer.parseInt(args[2]);
53 } else {
54 firstMessageSize = 256;
55 }
56
57
58 ClientBootstrap bootstrap = new ClientBootstrap(
59 new NioClientSocketChannelFactory(
60 Executors.newCachedThreadPool(),
61 Executors.newCachedThreadPool()));
62
63
64 bootstrap.setPipelineFactory(new ChannelPipelineFactory() {
65 public ChannelPipeline getPipeline() throws Exception {
66 return Channels.pipeline(
67 new DiscardClientHandler(firstMessageSize));
68 }
69 });
70
71
72 ChannelFuture future = bootstrap.connect(new InetSocketAddress(host, port));
73
74
75 future.getChannel().getCloseFuture().awaitUninterruptibly();
76
77
78 bootstrap.releaseExternalResources();
79 }
80 }