List of usage examples for io.netty.handler.timeout ReadTimeoutHandler ReadTimeoutHandler
public ReadTimeoutHandler(int timeoutSeconds)
From source file:privateprotocal.client.NettyClient.java
License:Apache License
public void connect(int port, String host) throws Exception { // ?NIO/* w ww. j a v a2 s .c o m*/ try { Bootstrap b = new Bootstrap(); b.group(group).channel(NioSocketChannel.class).option(ChannelOption.TCP_NODELAY, true) .handler(new ChannelInitializer<SocketChannel>() { @Override public void initChannel(SocketChannel ch) throws Exception { ch.pipeline().addLast(new NettyMessageDecoder(1024 * 1024, 4, 4)); ch.pipeline().addLast("MessageEncoder", new NettyMessageEncoder()); ch.pipeline().addLast("readTimeoutHandler", new ReadTimeoutHandler(50)); ch.pipeline().addLast("LoginAuthHandler", new LoginAuthReqHandler()); ch.pipeline().addLast("HeartBeatHandler", new HeartBeatReqHandler()); } }); // ?? ChannelFuture future = b.connect(new InetSocketAddress(host, port), new InetSocketAddress(NettyConstant.LOCALIP, NettyConstant.LOCAL_PORT)).sync(); future.channel().closeFuture().sync(); } finally { // ???????? executor.execute(new Runnable() { @Override public void run() { try { TimeUnit.SECONDS.sleep(1); try { connect(NettyConstant.PORT, NettyConstant.REMOTEIP);// ??? } catch (Exception e) { e.printStackTrace(); } } catch (InterruptedException e) { e.printStackTrace(); } } }); } }
From source file:uk.co.thinkofdeath.prismarine.network.ConnectionInitializer.java
License:Apache License
@Override protected void initChannel(SocketChannel ch) throws Exception { logger.info("Connection(" + ch.remoteAddress() + ")"); ChannelPipeline pipeline = ch.pipeline(); pipeline.addLast("timeout", new ReadTimeoutHandler(30)); pipeline.addLast("frame-codec", new VarIntFrameCodec()); pipeline.addLast("packet-codec", new PacketCodec(Protocol.HANDSHAKING, networkManager.getIncomingPacketType())); pipeline.addLast("handler", new NetworkHandler(networkManager, ch, initialHandler.get())); }
From source file:uk.co.thinkofdeath.thinkcraft.bukkit.web.ServerChannelInitializer.java
License:Apache License
@Override protected void initChannel(SocketChannel socketChannel) throws Exception { ChannelPipeline pipeline = socketChannel.pipeline(); pipeline.addLast("timeout", new ReadTimeoutHandler(15)); pipeline.addLast("codec-http", new HttpServerCodec()); pipeline.addLast("aggregator", new HttpObjectAggregator(65536)); pipeline.addLast("handler", new HTTPHandler(plugin)); pipeline.addLast("websocket", new WebSocketServerProtocolHandler("/server")); pipeline.addLast("packet-decoder", new PacketDecoder()); pipeline.addLast("packet-encoder", new PacketEncoder()); pipeline.addLast("packet-handler", new ClientHandler(socketChannel, plugin)); socketChannel.config().setAllocator(PooledByteBufAllocator.DEFAULT); plugin.getWebHandler().getChannelGroup().add(socketChannel); }