Simplify the echo client example
This commit is contained in:
parent
6eb540ca40
commit
e16c835780
@ -20,7 +20,6 @@ import io.netty.channel.ChannelBootstrap;
|
|||||||
import io.netty.channel.ChannelFuture;
|
import io.netty.channel.ChannelFuture;
|
||||||
import io.netty.channel.ChannelInitializer;
|
import io.netty.channel.ChannelInitializer;
|
||||||
import io.netty.channel.ChannelOption;
|
import io.netty.channel.ChannelOption;
|
||||||
import io.netty.channel.EventLoop;
|
|
||||||
import io.netty.channel.socket.nio.NioSocketChannel;
|
import io.netty.channel.socket.nio.NioSocketChannel;
|
||||||
import io.netty.channel.socket.nio.SelectorEventLoop;
|
import io.netty.channel.socket.nio.SelectorEventLoop;
|
||||||
import io.netty.handler.logging.LogLevel;
|
import io.netty.handler.logging.LogLevel;
|
||||||
@ -47,12 +46,10 @@ public class EchoClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void run() throws Exception {
|
public void run() throws Exception {
|
||||||
// Create the required event loop.
|
// Configure the client.
|
||||||
EventLoop loop = new SelectorEventLoop();
|
ChannelBootstrap b = new ChannelBootstrap();
|
||||||
try {
|
try {
|
||||||
// Configure the client.
|
b.eventLoop(new SelectorEventLoop())
|
||||||
ChannelBootstrap b = new ChannelBootstrap();
|
|
||||||
b.eventLoop(loop)
|
|
||||||
.channel(new NioSocketChannel())
|
.channel(new NioSocketChannel())
|
||||||
.option(ChannelOption.TCP_NODELAY, true)
|
.option(ChannelOption.TCP_NODELAY, true)
|
||||||
.remoteAddress(new InetSocketAddress(host, port))
|
.remoteAddress(new InetSocketAddress(host, port))
|
||||||
@ -72,7 +69,7 @@ public class EchoClient {
|
|||||||
f.channel().closeFuture().sync();
|
f.channel().closeFuture().sync();
|
||||||
} finally {
|
} finally {
|
||||||
// Shut down the event loop to terminate all threads.
|
// Shut down the event loop to terminate all threads.
|
||||||
loop.shutdown();
|
b.shutdown();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user