Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revision of 4.x guide #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 12 additions & 18 deletions 4.0/guide/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ <h3>2. Writing a Discard Server</h3>
<span class="linenumber"> </span><span class="linenumber-separator"> </span>public class DiscardServerHandler extends <a href="http://static.netty.io/4.0/api/io/netty/channel/ChannelInboundByteHandlerAdapter.html"><code class="classname">ChannelInboundByteHandlerAdapter</code></a> {<a name="example.discard.co1" id="example.discard.co1"></a><img src="http://docbook.github.com/release/2.0.3/base/img/1.png" alt="1" border="0" />
<span class="linenumber"> 4</span><span class="linenumber-separator"> </span>
<span class="linenumber"> </span><span class="linenumber-separator"> </span> @Override
<span class="linenumber"> 6</span><span class="linenumber-separator"> </span> public void inboundBufferUpdate(<a href="http://static.netty.io/4.0/api/io/netty/channel/ChannelHandlerContext.html"><code class="interfacename">ChannelHandlerContext</code></a> ctx, <a href="http://static.netty.io/4.0/api/io/netty/buffer/ByteBuf.html"><code class="interfacename">ByteBuf</code></a> in) {<a name="example.discard.co2" id="example.discard.co2"></a><img src="http://docbook.github.com/release/2.0.3/base/img/2.png" alt="2" border="0" />
<span class="linenumber"> 6</span><span class="linenumber-separator"> </span> public void inboundBufferUpdate(<a href="http://static.netty.io/4.0/api/io/netty/channel/ChannelHandlerContext.html"><code class="interfacename">ChannelHandlerContext</code></a> ctx, <a href="http://static.netty.io/4.0/api/io/netty/buffer/ByteBuf.html"><code class="interfacename">ByteBuf</code></a> in) throws Exception {<a name="example.discard.co2" id="example.discard.co2"></a><img src="http://docbook.github.com/release/2.0.3/base/img/2.png" alt="2" border="0" />
<span class="linenumber"> </span><span class="linenumber-separator"> </span> in.clear();
<span class="linenumber"> 8</span><span class="linenumber-separator"> </span> }
<span class="linenumber"> </span><span class="linenumber-separator"> </span>
Expand All @@ -281,13 +281,7 @@ <h3>2. Writing a Discard Server</h3>
</td>
<td class="callout-body" valign="baseline" align="left">
<p>
<code class="classname">DiscardServerHandler</code> extends
, which is an implementation of
. provides various event
handler methods that you can override. For now, it is just enough
to extend <a href="http://static.netty.io/4.0/api/io/netty/channel/ChannelInboundByteHandlerAdapter.html"><code class="classname">ChannelInboundByteHandlerAdapter</code></a> rather than to implement
the handler interfaces by yourself.

<code class="classname">DiscardServerHandler</code> extends <a href="http://static.netty.io/4.0/api/io/netty/channel/ChannelInboundByteHandlerAdapter.html"><code class="classname">ChannelInboundByteHandlerAdapter</code></a>, which is an implementation of <a href="http://static.netty.io/4.0/api/io/netty/channel/ChannelStateHandler.html"><code class="classname">ChannelStateHandler</code></a>. <a href="http://static.netty.io/4.0/api/io/netty/channel/ChannelStateHandler.html"><code class="classname">ChannelStateHandler</code></a> provides various event handler methods that you can override. For now, it is just enough to extend <a href="http://static.netty.io/4.0/api/io/netty/channel/ChannelInboundByteHandlerAdapter.html"><code class="classname">ChannelInboundByteHandlerAdapter</code></a> rather than to implement the handler interfaces by yourself.
</p>
</td>
</tr>
Expand Down Expand Up @@ -344,24 +338,24 @@ <h3>2. Writing a Discard Server</h3>
<span class="linenumber"> </span><span class="linenumber-separator"> </span>
<span class="linenumber"> 8</span><span class="linenumber-separator"> </span> public static void main(String[] args) throws Exception {
<span class="linenumber"> </span><span class="linenumber-separator"> </span> <a href="http://static.netty.io/4.0/api/io/netty/bootstrap/ServerBootstrap.html"><code class="classname">ServerBootstrap</code></a> bootstrap =
<span class="linenumber"> 10</span><span class="linenumber-separator"> </span> new <a name="example.discard2.co1" id="example.discard2.co1"></a><img src="http://docbook.github.com/release/2.0.3/base/img/4.png" alt="4" border="0" />();
<span class="linenumber"> 10</span><span class="linenumber-separator"> </span> new <a href="http://static.netty.io/4.0/api/io/netty/bootstrap/ServerBootstrap.html"><code class="classname">ServerBootstrap</code></a><a name="example.discard2.co1" id="example.discard2.co1"></a><img src="http://docbook.github.com/release/2.0.3/base/img/4.png" alt="4" border="0" />();
<span class="linenumber"> </span><span class="linenumber-separator"> </span> try {
<span class="linenumber"> 12</span><span class="linenumber-separator"> </span> bootstrap.group(new <a href="http://static.netty.io/4.0/api/io/netty/channel/nio/NioEventLoopGroup.html"><code class="classname">NioEventLoopGroup</code></a>(), new <a href="http://static.netty.io/4.0/api/io/netty/channel/nio/NioEventLoopGroup.html"><code class="classname">NioEventLoopGroup</code></a><a name="example.discard2.co2" id="example.discard2.co2"></a><img src="http://docbook.github.com/release/2.0.3/base/img/5.png" alt="5" border="0" />();
<span class="linenumber"> </span><span class="linenumber-separator"> </span> .channel(<a name="example.discard2.co3" id="example.discard2.co3"></a><img src="http://docbook.github.com/release/2.0.3/base/img/6.png" alt="6" border="0" />)
<span class="linenumber"> 12</span><span class="linenumber-separator"> </span> bootstrap.group(new <a href="http://static.netty.io/4.0/api/io/netty/channel/nio/NioEventLoopGroup.html"><code class="classname">NioEventLoopGroup</code></a>(), new <a href="http://static.netty.io/4.0/api/io/netty/channel/nio/NioEventLoopGroup.html"><code class="classname">NioEventLoopGroup</code></a><a name="example.discard2.co2" id="example.discard2.co2"></a><img src="http://docbook.github.com/release/2.0.3/base/img/5.png" alt="5" border="0" />())
<span class="linenumber"> </span><span class="linenumber-separator"> </span> .channel(<a href="http://static.netty.io/4.0/api/io/netty/socket/nio/NioServerSocketChannel.html"><code class="classname">NioServerSocketChannel</code></a>.class<a name="example.discard2.co3" id="example.discard2.co3"></a><img src="http://docbook.github.com/release/2.0.3/base/img/6.png" alt="6" border="0" />)
<span class="linenumber"> 14</span><span class="linenumber-separator"> </span> .childHandler(new <a href="http://static.netty.io/4.0/api/io/netty/channel/ChannelInitializer.html"><code class="classname">ChannelInitializer</code></a>&lt;SocketChannel&gt;() {<a name="example.discard2.co4" id="example.discard2.co4"></a><img src="http://docbook.github.com/release/2.0.3/base/img/7.png" alt="7" border="0" />
<span class="linenumber"> </span><span class="linenumber-separator"> </span> @Override
<span class="linenumber"> 16</span><span class="linenumber-separator"> </span> public void initChannel(SocketChannel channel) throws Exception {
<span class="linenumber"> </span><span class="linenumber-separator"> </span> channel.pipeline().addLast(new DiscardServerHandler());
<span class="linenumber"> 18</span><span class="linenumber-separator"> </span> }
<span class="linenumber"> </span><span class="linenumber-separator"> </span> })
<span class="linenumber"> 20</span><span class="linenumber-separator"> </span> .setChildOption(.TCP_NO_DELAY, true)<a name="example.discard2.co5" id="example.discard2.co5"></a><img src="http://docbook.github.com/release/2.0.3/base/img/8.png" alt="8" border="0" />
<span class="linenumber"> </span><span class="linenumber-separator"> </span> .setChildOption(.KEEP_ALIVE, true)
<span class="linenumber"> 20</span><span class="linenumber-separator"> </span> .childOption(ChannelOption.<a href="http://static.netty.io/4.0/api/io/netty/channel/ChannelOption.html#TCP_NODELAY">TCP_NODELAY</a>, true)<a name="example.discard2.co5" id="example.discard2.co5"></a><img src="http://docbook.github.com/release/2.0.3/base/img/8.png" alt="8" border="0" />
<span class="linenumber"> </span><span class="linenumber-separator"> </span> .childOption(ChannelOption.<a href="http://static.netty.io/4.0/api/io/netty/channel/ChannelOption.html#SO_KEEPALIVE">SO_KEEPALIVE</a>, true);
<span class="linenumber"> 22</span><span class="linenumber-separator"> </span>
<span class="linenumber"> </span><span class="linenumber-separator"> </span> ChannelFuture future = bootstrap.bind(new InetSocketAddress(8080)).sync();<a name="example.discard2.co6" id="example.discard2.co6"></a><img src="http://docbook.github.com/release/2.0.3/base/img/9.png" alt="9" border="0" />
<span class="linenumber"> 24</span><span class="linenumber-separator"> </span>
<span class="linenumber"> </span><span class="linenumber-separator"> </span> future.channel().closeFuture().sync();
<span class="linenumber"> 26</span><span class="linenumber-separator"> </span> } finally {
<span class="linenumber"> </span><span class="linenumber-separator"> </span> b.shutdown();
<span class="linenumber"> </span><span class="linenumber-separator"> </span> bootstrap.shutdown();
<span class="linenumber"> 28</span><span class="linenumber-separator"> </span> }
<span class="linenumber"> </span><span class="linenumber-separator"> </span> }
<span class="linenumber"> 30</span><span class="linenumber-separator"> </span>}</pre></div>
Expand Down Expand Up @@ -501,8 +495,8 @@ <h3>3. Looking into the Received Data</h3>

</p>
<div class="programlisting"><pre><span class="linenumber"> 1</span><span class="linenumber-separator"> </span>@Override
<span class="linenumber"> 2</span><span class="linenumber-separator"> </span>public void inboundBufferUpdated(<a href="http://static.netty.io/4.0/api/io/netty/channel/ChannelHandlerContext.html"><code class="interfacename">ChannelHandlerContext</code></a> ctx, <a href="http://static.netty.io/4.0/api/io/netty/buffer/ByteBuf.html"><code class="interfacename">ByteBuf</code></a> in) {
<span class="linenumber"> </span><span class="linenumber-separator"> </span> while(in.readable()) {
<span class="linenumber"> 2</span><span class="linenumber-separator"> </span>public void inboundBufferUpdated(<a href="http://static.netty.io/4.0/api/io/netty/channel/ChannelHandlerContext.html"><code class="interfacename">ChannelHandlerContext</code></a> ctx, <a href="http://static.netty.io/4.0/api/io/netty/buffer/ByteBuf.html"><code class="interfacename">ByteBuf</code></a> in) throws Exception {
<span class="linenumber"> </span><span class="linenumber-separator"> </span> while(in.isReadable()) {
<span class="linenumber"> 4</span><span class="linenumber-separator"> </span> System.out.println((char) buf.readByte());
<span class="linenumber"> </span><span class="linenumber-separator"> </span> System.out.flush();
<span class="linenumber"> 6</span><span class="linenumber-separator"> </span> }
Expand Down Expand Up @@ -605,7 +599,7 @@ <h3>5. Writing a Time Server</h3>
</p>
<div class="programlisting"><pre><span class="linenumber"> 1</span><span class="linenumber-separator"> </span>package io.netty.example.time;
<span class="linenumber"> 2</span><span class="linenumber-separator"> </span>
<span class="linenumber"> </span><span class="linenumber-separator"> </span>public class TimeServerHandler extends {
<span class="linenumber"> </span><span class="linenumber-separator"> </span>public class TimeServerHandler extends <a href="http://static.netty.io/4.0/api/io/netty/channel/ChannelInboundByteHandlerAdapter.html"><code class="classname">ChannelInboundByteHandlerAdapter</code></a> {
<span class="linenumber"> 4</span><span class="linenumber-separator"> </span>
<span class="linenumber"> </span><span class="linenumber-separator"> </span> @Override
<span class="linenumber"> 6</span><span class="linenumber-separator"> </span> public void channelActive(<a href="http://static.netty.io/4.0/api/io/netty/channel/ChannelHandlerContext.html"><code class="interfacename">ChannelHandlerContext</code></a> ctx) {<a name="example.time.co1" id="example.time.co1"></a><img src="http://docbook.github.com/release/2.0.3/base/img/11.png" alt="11"
Expand Down Expand Up @@ -2249,4 +2243,4 @@ <h3>4. How do I pass data between handlers in the same Channel?</h3>
</article>
</article>
</body>
</html>
</html>