You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by bu...@apache.org on 2012/11/15 14:10:46 UTC

svn commit: r838430 [7/12] - in /websites/staging/mina/trunk/content: ./ mina-project/ mina-project/userguide/ mina-project/userguide/ch1-getting-started/ mina-project/userguide/ch10-executor-filter/ mina-project/userguide/ch11-ssl-filter/ mina-project...

Added: websites/staging/mina/trunk/content/mina-project/userguide/ch2-basics/sample-tcp-server.html
==============================================================================
--- websites/staging/mina/trunk/content/mina-project/userguide/ch2-basics/sample-tcp-server.html (added)
+++ websites/staging/mina/trunk/content/mina-project/userguide/ch2-basics/sample-tcp-server.html Thu Nov 15 13:10:37 2012
@@ -0,0 +1,386 @@
+<!DOCTYPE html>
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You under the Apache License, Version 2.0
+    (the "License"); you may not use this file except in compliance with
+    the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<html>
+<head>
+	<title>Sample TCP Server &mdash; Apache MINA</title>
+	
+		<link href="./../../../css/common.css" rel="stylesheet" type="text/css">
+		<link href="./../../../css/mina.css" rel="stylesheet" type="text/css">
+	
+</head>
+  <body>
+    <div id="container">
+      <div id="header">
+        <div id="subProjectsNavBar">
+          <a href="./../../../">
+            
+              <strong>Apache MINA Project</strong>
+            
+          </a>
+          &nbsp;|&nbsp;
+          <a href="./../../../mina/index.html">
+            
+              MINA
+            
+          </a>
+          &nbsp;|&nbsp;
+          <a href="./../../../asyncweb/index.html">
+            
+              AsyncWeb
+            
+          </a>
+          &nbsp;|&nbsp;
+          <a href="./../../../ftpserver/index.html">
+            
+              FtpServer
+            
+          </a>
+          &nbsp;|&nbsp;
+          <a href="./../../../sshd/index.html">
+            
+              SSHD
+            
+          </a>
+          &nbsp;|&nbsp;
+          <a href="./../../../vysper/index.html">
+            
+              Vysper
+            
+          </a>
+        </div><!-- subProjectsNavBar -->
+      </div><!-- header -->
+      <div id="content">
+        <div id="leftColumn">
+                              
+          
+          
+          
+          
+          
+            <div id="navigation">
+
+    <h5>Latest Downloads</h5>
+    <ul>
+        <li><a href="./../../../downloads-mina.html">Mina 2.0.7</a></li>
+        <li><a href="./../../../downloads-ftpserver.html">FtpServer 1.0.6</a></li>
+        <li><a href="./../../../downloads-sshd.html">SSHD 0.8.0</a></li>
+        <li><a href="./../../../downloads-vysper.html">Vysper 0.7</a></li>
+    </ul>
+    <h5>Projects</h5>
+    <ul>
+        <li><a href="./../../../mina/index.html">MINA</a></li>
+        <li><a href="./../../../asyncweb/index.html">AsyncWeb</a></li>
+        <li><a href="./../../../ftpserver/index.html">FtpServer</a></li>
+        <li><a href="./../../../sshd/index.html">SSHD</a></li>
+        <li><a href="./../../../vysper/index.html">Vysper</a></li>
+    </ul>
+
+    <h5>Community</h5>
+    <ul>
+      <li><a href="./../../../contributors.html" class="external-link" rel="nofollow">Team</a></li>
+      <li><a href="http://www.apache.org/licenses/" class="external-link" rel="nofollow">License</a></li>
+      <li><a href="http://www.apache.org/foundation/contributing.html" class="external-link" rel="nofollow">Contributing</a></li>
+      <li><a href="http://www.apache.org/" title="Apache Software Foundation" class="external-link" rel="nofollow">ASF main site</a></li>
+      <li><a href="http://www.apache.org/foundation/thanks.html" class="external-link" rel="nofollow">Thanks</a></li>
+      <li><a href="http://www.apache.org/foundation/sponsorship.html" title="The ASF sponsorship program" class="external-link" rel="nofollow">Sponsorship program</a></li>
+      <li><a href="http://www.apache.org/security/" class="external-link" rel="nofollow">Security</a></li>
+    </ul>
+
+    <h3><a name="Navigation-Upcoming"></a>Upcoming</h3>
+
+</div>
+
+<!-- navigation -->
+          
+        </div><!-- leftColumn -->
+      <div id="rightColumn">
+
+
+
+    <div class="nav">
+        <div class="nav_prev">
+        
+            <a href="application-architecture.html">Application Architecture</a>
+		
+        </div>
+        <div class="nav_up">
+        
+            <a href="ch2-basics.html">Chapter 2 - Basics</a>
+		
+        </div>
+        <div class="nav_next">
+        
+            <a href="sample-tcp-client.html">Sample TCP Client</a>
+		
+        </div>
+        <div class="clearfix"></div>
+    </div>
+
+
+<h1 id="sample-tcp-server">Sample TCP Server</h1>
+<p>This tutorial will walk you through the process of building a MINA based program.  This tutorial will walk through building a time server.  The following prerequisites are required for this tutorial:</p>
+<ul>
+<li>MINA 2.x Core</li>
+<li>JDK 1.5 or greater</li>
+<li>SLF4J 1.3.0 or greater<ul>
+<li><strong>Log4J 1.2</strong> users: slf4j-api.jar, slf4j-log4j12.jar, and <a href="http://logging.apache.org/log4j/docs/">Log4J</a> 1.2.x</li>
+<li><strong>Log4J 1.3</strong> users: slf4j-api.jar, slf4j-log4j13.jar, and <a href="http://logging.apache.org/log4j/docs/">Log4J</a> 1.3.x</li>
+<li><strong>java.util.logging</strong> users: slf4j-api.jar and slf4j-jdk14.jar</li>
+<li><strong>IMPORTANT</strong>: Please make sure you are using the right slf4j-*.jar that matches to your logging framework.</li>
+</ul>
+</li>
+</ul>
+<p>For instance, slf4j-log4j12.jar and log4j-1.3.x.jar can not be used together, and will malfunction.</p>
+<p>We have tested this program on both Windows© 2000 professional and linux.  If you have any problems getting this program to work, please do not hesitate to <a href="{{base}}contact.html">contact us</a> in order to talk to the MINA developers.  Also, this tutorial has tried to remain independent of development environments (IDE, editors..etc).  This tutorial will work with any environment that you are comfortable with.  Compilation commands and steps to execute the program have been removed for brevity.  If you need help learning how to either compile or execute java programs, please consult the <a href="http://java.sun.com/docs/books/tutorial/">Java tutorial</a>.</p>
+<h2 id="writing-the-mina-time-server">Writing the MINA time server</h2>
+<p>We will begin by creating a file called MinaTimeServer.java. The initial code can be found below:</p>
+<div class="codehilite"><pre><span class="kd">public</span> <span class="kd">class</span> <span class="nc">MinaTimeServer</span> <span class="o">{</span>
+    <span class="kd">public</span> <span class="kd">static</span> <span class="kt">void</span> <span class="nf">main</span><span class="o">(</span><span class="n">String</span><span class="o">[]</span> <span class="n">args</span><span class="o">)</span> <span class="o">{</span>
+        <span class="c1">// code will go here next</span>
+    <span class="o">}</span>
+<span class="o">}</span>
+</pre></div>
+
+
+<p>This code should be straightforward to all.  We are simply defining a main method that will be used to kick off the program.  At this point, we will begin to add the code that will make up our server.  First off, we need an object that will be used to listen for incoming connections.  Since this program will be TCP/IP based, we will add a SocketAcceptor to our program.</p>
+<div class="codehilite"><pre><span class="kn">import</span> <span class="nn">org.apache.mina.transport.socket.nio.NioSocketAcceptor</span><span class="o">;</span>
+
+<span class="kd">public</span> <span class="kd">class</span> <span class="nc">MinaTimeServer</span>
+<span class="o">{</span>
+    <span class="kd">public</span> <span class="kd">static</span> <span class="kt">void</span> <span class="nf">main</span><span class="o">(</span> <span class="n">String</span><span class="o">[]</span> <span class="n">args</span> <span class="o">)</span>
+    <span class="o">{</span>
+        <span class="n">IoAcceptor</span> <span class="n">acceptor</span> <span class="o">=</span> <span class="k">new</span> <span class="n">NioSocketAcceptor</span><span class="o">();</span>
+    <span class="o">}</span>
+<span class="o">}</span>
+</pre></div>
+
+
+<p>With the NioSocketAcceptor class in place, we can go ahead and define the handler class and bind the NioSocketAcceptor to a port :</p>
+<div class="codehilite"><pre><span class="kn">import</span> <span class="nn">java.net.InetSocketAddress</span><span class="o">;</span>
+
+<span class="kn">import</span> <span class="nn">org.apache.mina.core.service.IoAcceptor</span><span class="o">;</span>
+<span class="kn">import</span> <span class="nn">org.apache.mina.transport.socket.nio.NioSocketAcceptor</span><span class="o">;</span>
+
+<span class="kd">public</span> <span class="kd">class</span> <span class="nc">MinaTimeServer</span>
+<span class="o">{</span>
+    <span class="kd">private</span> <span class="kd">static</span> <span class="kd">final</span> <span class="kt">int</span> <span class="n">PORT</span> <span class="o">=</span> <span class="mi">9123</span><span class="o">;</span>
+    <span class="kd">public</span> <span class="kd">static</span> <span class="kt">void</span> <span class="nf">main</span><span class="o">(</span> <span class="n">String</span><span class="o">[]</span> <span class="n">args</span> <span class="o">)</span> <span class="kd">throws</span> <span class="n">IOException</span>
+    <span class="o">{</span>
+        <span class="n">IoAcceptor</span> <span class="n">acceptor</span> <span class="o">=</span> <span class="k">new</span> <span class="n">NioSocketAcceptor</span><span class="o">();</span>
+        <span class="n">acceptor</span><span class="o">.</span><span class="na">bind</span><span class="o">(</span> <span class="k">new</span> <span class="n">InetSocketAddress</span><span class="o">(</span><span class="n">PORT</span><span class="o">)</span> <span class="o">);</span>
+    <span class="o">}</span>
+<span class="o">}</span>
+</pre></div>
+
+
+<p>As you see, there is a call to acceptor.setLocalAddress( new InetSocketAddress(PORT) );. This method defines what host and port this server will listen on. The final method is a call to IoAcceptor.bind(). This method will bind to the specified port and start processing of remote clients.</p>
+<p>Next we add a filter to the configuration. This filter will log all information such as newly created sessions, messages received, messages sent, session closed. The next filter is a ProtocolCodecFilter. This filter will translate binary or protocol specific data into message object and vice versa. We use an existing TextLine factory because it will handle text base message for you (you don't have to write the codec part)</p>
+<div class="codehilite"><pre><span class="kn">import</span> <span class="nn">java.io.IOException</span><span class="o">;</span>
+<span class="kn">import</span> <span class="nn">java.net.InetSocketAddress</span><span class="o">;</span>
+<span class="kn">import</span> <span class="nn">java.nio.charset.Charset</span><span class="o">;</span>
+
+<span class="kn">import</span> <span class="nn">org.apache.mina.core.service.IoAcceptor</span><span class="o">;</span>
+<span class="kn">import</span> <span class="nn">org.apache.mina.filter.codec.ProtocolCodecFilter</span><span class="o">;</span>
+<span class="kn">import</span> <span class="nn">org.apache.mina.filter.codec.textline.TextLineCodecFactory</span><span class="o">;</span>
+<span class="kn">import</span> <span class="nn">org.apache.mina.filter.logging.LoggingFilter</span><span class="o">;</span>
+<span class="kn">import</span> <span class="nn">org.apache.mina.transport.socket.nio.NioSocketAcceptor</span><span class="o">;</span>
+
+<span class="kd">public</span> <span class="kd">class</span> <span class="nc">MinaTimeServer</span>
+<span class="o">{</span>
+    <span class="kd">public</span> <span class="kd">static</span> <span class="kt">void</span> <span class="nf">main</span><span class="o">(</span> <span class="n">String</span><span class="o">[]</span> <span class="n">args</span> <span class="o">)</span>
+    <span class="o">{</span>
+        <span class="n">IoAcceptor</span> <span class="n">acceptor</span> <span class="o">=</span> <span class="k">new</span> <span class="n">NioSocketAcceptor</span><span class="o">();</span>
+        <span class="n">acceptor</span><span class="o">.</span><span class="na">getFilterChain</span><span class="o">().</span><span class="na">addLast</span><span class="o">(</span> <span class="s">&quot;logger&quot;</span><span class="o">,</span> <span class="k">new</span> <span class="n">LoggingFilter</span><span class="o">()</span> <span class="o">);</span>
+        <span class="n">acceptor</span><span class="o">.</span><span class="na">getFilterChain</span><span class="o">().</span><span class="na">addLast</span><span class="o">(</span> <span class="s">&quot;codec&quot;</span><span class="o">,</span> <span class="k">new</span> <span class="n">ProtocolCodecFilter</span><span class="o">(</span> <span class="k">new</span> <span class="n">TextLineCodecFactory</span><span class="o">(</span> <span class="n">Charset</span><span class="o">.</span><span class="na">forName</span><span class="o">(</span> <span class="s">&quot;UTF-8&quot;</span> <span class="o">))));</span>
+        <span class="n">acceptor</span><span class="o">.</span><span class="na">bind</span><span class="o">(</span> <span class="k">new</span> <span class="n">InetSocketAddress</span><span class="o">(</span><span class="n">PORT</span><span class="o">)</span> <span class="o">);</span>
+    <span class="o">}</span>
+<span class="o">}</span>
+</pre></div>
+
+
+<p>At this point, we will define the handler that will be used to service client connections and the requests for the current time. The handler class is a class that must implement the interface IoHandler. For almost all programs that use MINA, this becomes the workhorse of the program, as it services all incoming requests from the clients. For this tutorial, we will extend the class IoHandlerAdapter. This is a class that follows the <a href="http://en.wikipedia.org/wiki/Adapter_pattern">adapter design pattern</a> which simplifies the amount of code that needs to be written in order to satisfy the requirement of passing in a class that implements the IoHandler interface.</p>
+<div class="codehilite"><pre><span class="kn">import</span> <span class="nn">java.net.InetSocketAddress</span><span class="o">;</span>
+<span class="kn">import</span> <span class="nn">java.nio.charset.Charset</span><span class="o">;</span>
+
+<span class="kn">import</span> <span class="nn">org.apache.mina.core.service.IoAcceptor</span><span class="o">;</span>
+<span class="kn">import</span> <span class="nn">org.apache.mina.filter.codec.ProtocolCodecFilter</span><span class="o">;</span>
+<span class="kn">import</span> <span class="nn">org.apache.mina.filter.codec.textline.TextLineCodecFactory</span><span class="o">;</span>
+<span class="kn">import</span> <span class="nn">org.apache.mina.filter.logging.LoggingFilter</span><span class="o">;</span>
+<span class="kn">import</span> <span class="nn">org.apache.mina.transport.socket.nio.NioSocketAcceptor</span><span class="o">;</span>
+
+<span class="kd">public</span> <span class="kd">class</span> <span class="nc">MinaTimeServer</span>
+<span class="o">{</span>
+    <span class="kd">public</span> <span class="kd">static</span> <span class="kt">void</span> <span class="nf">main</span><span class="o">(</span> <span class="n">String</span><span class="o">[]</span> <span class="n">args</span> <span class="o">)</span> <span class="kd">throws</span> <span class="n">IOException</span>
+    <span class="o">{</span>
+        <span class="n">IoAcceptor</span> <span class="n">acceptor</span> <span class="o">=</span> <span class="k">new</span> <span class="n">NioSocketAcceptor</span><span class="o">();</span>
+        <span class="n">acceptor</span><span class="o">.</span><span class="na">getFilterChain</span><span class="o">().</span><span class="na">addLast</span><span class="o">(</span> <span class="s">&quot;logger&quot;</span><span class="o">,</span> <span class="k">new</span> <span class="n">LoggingFilter</span><span class="o">()</span> <span class="o">);</span>
+        <span class="n">acceptor</span><span class="o">.</span><span class="na">getFilterChain</span><span class="o">().</span><span class="na">addLast</span><span class="o">(</span> <span class="s">&quot;codec&quot;</span><span class="o">,</span> <span class="k">new</span> <span class="n">ProtocolCodecFilter</span><span class="o">(</span> <span class="k">new</span> <span class="n">TextLineCodecFactory</span><span class="o">(</span> <span class="n">Charset</span><span class="o">.</span><span class="na">forName</span><span class="o">(</span> <span class="s">&quot;UTF-8&quot;</span> <span class="o">))));</span>
+        <span class="n">acceptor</span><span class="o">.</span><span class="na">setHandler</span><span class="o">(</span>  <span class="k">new</span> <span class="n">TimeServerHandler</span><span class="o">()</span> <span class="o">);</span>
+        <span class="n">acceptor</span><span class="o">.</span><span class="na">bind</span><span class="o">(</span> <span class="k">new</span> <span class="n">InetSocketAddress</span><span class="o">(</span><span class="n">PORT</span><span class="o">)</span> <span class="o">);</span>
+    <span class="o">}</span>
+<span class="o">}</span>
+</pre></div>
+
+
+<p>We will now add in the NioSocketAcceptor configuration. This will allow us to make socket-specific settings for the socket that will be used to accept connections from clients.</p>
+<div class="codehilite"><pre><span class="kn">import</span> <span class="nn">java.net.InetSocketAddress</span><span class="o">;</span>
+<span class="kn">import</span> <span class="nn">java.nio.charset.Charset</span><span class="o">;</span>
+
+<span class="kn">import</span> <span class="nn">org.apache.mina.core.session.IdleStatus</span><span class="o">;</span>
+<span class="kn">import</span> <span class="nn">org.apache.mina.core.service.IoAcceptor</span><span class="o">;</span>
+<span class="kn">import</span> <span class="nn">org.apache.mina.filter.codec.ProtocolCodecFilter</span><span class="o">;</span>
+<span class="kn">import</span> <span class="nn">org.apache.mina.filter.codec.textline.TextLineCodecFactory</span><span class="o">;</span>
+<span class="kn">import</span> <span class="nn">org.apache.mina.filter.logging.LoggingFilter</span><span class="o">;</span>
+<span class="kn">import</span> <span class="nn">org.apache.mina.transport.socket.nio.NioSocketAcceptor</span><span class="o">;</span>
+
+<span class="kd">public</span> <span class="kd">class</span> <span class="nc">MinaTimeServer</span>
+<span class="o">{</span>
+    <span class="kd">public</span> <span class="kd">static</span> <span class="kt">void</span> <span class="nf">main</span><span class="o">(</span> <span class="n">String</span><span class="o">[]</span> <span class="n">args</span> <span class="o">)</span> <span class="kd">throws</span> <span class="n">IOException</span>
+    <span class="o">{</span>
+        <span class="n">IoAcceptor</span> <span class="n">acceptor</span> <span class="o">=</span> <span class="k">new</span> <span class="n">NioSocketAcceptor</span><span class="o">();</span>
+        <span class="n">acceptor</span><span class="o">.</span><span class="na">getFilterChain</span><span class="o">().</span><span class="na">addLast</span><span class="o">(</span> <span class="s">&quot;logger&quot;</span><span class="o">,</span> <span class="k">new</span> <span class="n">LoggingFilter</span><span class="o">()</span> <span class="o">);</span>
+        <span class="n">acceptor</span><span class="o">.</span><span class="na">getFilterChain</span><span class="o">().</span><span class="na">addLast</span><span class="o">(</span> <span class="s">&quot;codec&quot;</span><span class="o">,</span> <span class="k">new</span> <span class="n">ProtocolCodecFilter</span><span class="o">(</span> <span class="k">new</span> <span class="n">TextLineCodecFactory</span><span class="o">(</span> <span class="n">Charset</span><span class="o">.</span><span class="na">forName</span><span class="o">(</span> <span class="s">&quot;UTF-8&quot;</span> <span class="o">))));</span>
+        <span class="n">acceptor</span><span class="o">.</span><span class="na">setHandler</span><span class="o">(</span>  <span class="k">new</span> <span class="n">TimeServerHandler</span><span class="o">()</span> <span class="o">);</span>
+        <span class="n">acceptor</span><span class="o">.</span><span class="na">getSessionConfig</span><span class="o">().</span><span class="na">setReadBufferSize</span><span class="o">(</span> <span class="mi">2048</span> <span class="o">);</span>
+        <span class="n">acceptor</span><span class="o">.</span><span class="na">getSessionConfig</span><span class="o">().</span><span class="na">setIdleTime</span><span class="o">(</span> <span class="n">IdleStatus</span><span class="o">.</span><span class="na">BOTH_IDLE</span><span class="o">,</span> <span class="mi">10</span> <span class="o">);</span>
+        <span class="n">acceptor</span><span class="o">.</span><span class="na">bind</span><span class="o">(</span> <span class="k">new</span> <span class="n">InetSocketAddress</span><span class="o">(</span><span class="n">PORT</span><span class="o">)</span> <span class="o">);</span>
+    <span class="o">}</span>
+<span class="o">}</span>
+</pre></div>
+
+
+<p>There are 2 new lines in the MinaTimeServer class. These methods set the set the IoHandler, input buffer size and the idle property for the sessions. The buffer size will be specified in order to tell the underlying operating system how much room to allocate for incoming data. The second line will specify when to check for idle sessions. In the call to setIdleTime, the first parameter defines what actions to check for when determining if a session is idle, the second parameter defines the length of time in seconds that must occur before a session is deemed to be idle.</p>
+<p>The code for the handler is shown below:</p>
+<div class="codehilite"><pre><span class="kn">import</span> <span class="nn">java.util.Date</span><span class="o">;</span>
+
+<span class="kn">import</span> <span class="nn">org.apache.mina.core.session.IdleStatus</span><span class="o">;</span>
+<span class="kn">import</span> <span class="nn">org.apache.mina.core.service.IoHandlerAdapter</span><span class="o">;</span>
+<span class="kn">import</span> <span class="nn">org.apache.mina.core.session.IoSession</span><span class="o">;</span>
+
+<span class="kd">public</span> <span class="kd">class</span> <span class="nc">TimeServerHandler</span> <span class="kd">extends</span> <span class="n">IoHandlerAdapter</span>
+<span class="o">{</span>
+    <span class="nd">@Override</span>
+    <span class="kd">public</span> <span class="kt">void</span> <span class="nf">exceptionCaught</span><span class="o">(</span> <span class="n">IoSession</span> <span class="n">session</span><span class="o">,</span> <span class="n">Throwable</span> <span class="n">cause</span> <span class="o">)</span> <span class="kd">throws</span> <span class="n">Exception</span>
+    <span class="o">{</span>
+        <span class="n">cause</span><span class="o">.</span><span class="na">printStackTrace</span><span class="o">();</span>
+    <span class="o">}</span>
+    <span class="nd">@Override</span>
+    <span class="kd">public</span> <span class="kt">void</span> <span class="nf">messageReceived</span><span class="o">(</span> <span class="n">IoSession</span> <span class="n">session</span><span class="o">,</span> <span class="n">Object</span> <span class="n">message</span> <span class="o">)</span> <span class="kd">throws</span> <span class="n">Exception</span>
+    <span class="o">{</span>
+        <span class="n">String</span> <span class="n">str</span> <span class="o">=</span> <span class="n">message</span><span class="o">.</span><span class="na">toString</span><span class="o">();</span>
+        <span class="k">if</span><span class="o">(</span> <span class="n">str</span><span class="o">.</span><span class="na">trim</span><span class="o">().</span><span class="na">equalsIgnoreCase</span><span class="o">(</span><span class="s">&quot;quit&quot;</span><span class="o">)</span> <span class="o">)</span> <span class="o">{</span>
+            <span class="n">session</span><span class="o">.</span><span class="na">close</span><span class="o">();</span>
+            <span class="k">return</span><span class="o">;</span>
+        <span class="o">}</span>
+        <span class="n">Date</span> <span class="n">date</span> <span class="o">=</span> <span class="k">new</span> <span class="n">Date</span><span class="o">();</span>
+        <span class="n">session</span><span class="o">.</span><span class="na">write</span><span class="o">(</span> <span class="n">date</span><span class="o">.</span><span class="na">toString</span><span class="o">()</span> <span class="o">);</span>
+        <span class="n">System</span><span class="o">.</span><span class="na">out</span><span class="o">.</span><span class="na">println</span><span class="o">(</span><span class="s">&quot;Message written...&quot;</span><span class="o">);</span>
+    <span class="o">}</span>
+    <span class="nd">@Override</span>
+    <span class="kd">public</span> <span class="kt">void</span> <span class="nf">sessionIdle</span><span class="o">(</span> <span class="n">IoSession</span> <span class="n">session</span><span class="o">,</span> <span class="n">IdleStatus</span> <span class="n">status</span> <span class="o">)</span> <span class="kd">throws</span> <span class="n">Exception</span>
+    <span class="o">{</span>
+        <span class="n">System</span><span class="o">.</span><span class="na">out</span><span class="o">.</span><span class="na">println</span><span class="o">(</span> <span class="s">&quot;IDLE &quot;</span> <span class="o">+</span> <span class="n">session</span><span class="o">.</span><span class="na">getIdleCount</span><span class="o">(</span> <span class="n">status</span> <span class="o">));</span>
+    <span class="o">}</span>
+<span class="o">}</span>
+</pre></div>
+
+
+<p>The methods used in this class are exceptionCaught, messageReceived and sessionIdle. exceptionCaught should always be defined in a handler to process and exceptions that are raised in the normal course of handling remote connections. If this method is not defined, exceptions may not get properly reported.</p>
+<p>The exceptionCaught method will simply print the stack trace of the error and close the session. For most programs, this will be standard practice unless the handler can recover from the exception condition.</p>
+<p>The messageReceived method will receive the data from the client and write back to the client the current time. If the message received from the client is the word "quit", then the session will be closed. This method will also print out the current time to the client. Depending on the protocol codec that you use, the object (second parameter) that gets passed in to this method will be different, as well as the object that you pass in to the session.write(Object) method. If you do not specify a protocol codec, you will most likely receive a IoBuffer object, and be required to write out a IoBuffer object.</p>
+<p>The sessionIdle method will be called once a session has remained idle for the amount of time specified in the call acceptor.getSessionConfig().setIdleTime( IdleStatus.BOTH_IDLE, 10 );.</p>
+<p>All that is left to do is define the socket address that the server will listen on, and actually make the call that will start the server. That code is shown below:</p>
+<div class="codehilite"><pre><span class="kn">import</span> <span class="nn">java.io.IOException</span><span class="o">;</span>
+<span class="kn">import</span> <span class="nn">java.net.InetSocketAddress</span><span class="o">;</span>
+<span class="kn">import</span> <span class="nn">java.nio.charset.Charset</span><span class="o">;</span>
+
+<span class="kn">import</span> <span class="nn">org.apache.mina.core.service.IoAcceptor</span><span class="o">;</span>
+<span class="kn">import</span> <span class="nn">org.apache.mina.core.session.IdleStatus</span><span class="o">;</span>
+<span class="kn">import</span> <span class="nn">org.apache.mina.filter.codec.ProtocolCodecFilter</span><span class="o">;</span>
+<span class="kn">import</span> <span class="nn">org.apache.mina.filter.codec.textline.TextLineCodecFactory</span><span class="o">;</span>
+<span class="kn">import</span> <span class="nn">org.apache.mina.filter.logging.LoggingFilter</span><span class="o">;</span>
+<span class="kn">import</span> <span class="nn">org.apache.mina.transport.socket.nio.NioSocketAcceptor</span><span class="o">;</span>
+
+<span class="kd">public</span> <span class="kd">class</span> <span class="nc">MinaTimeServer</span>
+<span class="o">{</span>
+    <span class="kd">private</span> <span class="kd">static</span> <span class="kd">final</span> <span class="kt">int</span> <span class="n">PORT</span> <span class="o">=</span> <span class="mi">9123</span><span class="o">;</span>
+    <span class="kd">public</span> <span class="kd">static</span> <span class="kt">void</span> <span class="nf">main</span><span class="o">(</span> <span class="n">String</span><span class="o">[]</span> <span class="n">args</span> <span class="o">)</span> <span class="kd">throws</span> <span class="n">IOException</span>
+    <span class="o">{</span>
+        <span class="n">IoAcceptor</span> <span class="n">acceptor</span> <span class="o">=</span> <span class="k">new</span> <span class="n">NioSocketAcceptor</span><span class="o">();</span>
+        <span class="n">acceptor</span><span class="o">.</span><span class="na">getFilterChain</span><span class="o">().</span><span class="na">addLast</span><span class="o">(</span> <span class="s">&quot;logger&quot;</span><span class="o">,</span> <span class="k">new</span> <span class="n">LoggingFilter</span><span class="o">()</span> <span class="o">);</span>
+        <span class="n">acceptor</span><span class="o">.</span><span class="na">getFilterChain</span><span class="o">().</span><span class="na">addLast</span><span class="o">(</span> <span class="s">&quot;codec&quot;</span><span class="o">,</span> <span class="k">new</span> <span class="n">ProtocolCodecFilter</span><span class="o">(</span> <span class="k">new</span> <span class="n">TextLineCodecFactory</span><span class="o">(</span> <span class="n">Charset</span><span class="o">.</span><span class="na">forName</span><span class="o">(</span> <span class="s">&quot;UTF-8&quot;</span> <span class="o">))));</span>
+        <span class="n">acceptor</span><span class="o">.</span><span class="na">setHandler</span><span class="o">(</span> <span class="k">new</span> <span class="n">TimeServerHandler</span><span class="o">()</span> <span class="o">);</span>
+        <span class="n">acceptor</span><span class="o">.</span><span class="na">getSessionConfig</span><span class="o">().</span><span class="na">setReadBufferSize</span><span class="o">(</span> <span class="mi">2048</span> <span class="o">);</span>
+        <span class="n">acceptor</span><span class="o">.</span><span class="na">getSessionConfig</span><span class="o">().</span><span class="na">setIdleTime</span><span class="o">(</span> <span class="n">IdleStatus</span><span class="o">.</span><span class="na">BOTH_IDLE</span><span class="o">,</span> <span class="mi">10</span> <span class="o">);</span>
+        <span class="n">acceptor</span><span class="o">.</span><span class="na">bind</span><span class="o">(</span> <span class="k">new</span> <span class="n">InetSocketAddress</span><span class="o">(</span><span class="n">PORT</span><span class="o">)</span> <span class="o">);</span>
+    <span class="o">}</span>
+<span class="o">}</span>
+</pre></div>
+
+
+<h2 id="try-out-the-time-server">Try out the Time server</h2>
+<p>At this point, we can go ahead and compile the program.  Once you have compiled the program you can run the program in order to test out what happens.  The easiest way to test the program is to start the program, and then telnet in to the program:</p>
+<table>
+<thead>
+<tr>
+<th>Client Output</th>
+<th>Server Output</th>
+</tr>
+</thead>
+<tbody>
+<tr>
+<td>user@myhost:~&gt; telnet 127.0.0.1 9123 <br/>Trying 127.0.0.1... <br/>Connected to 127.0.0.1. <br/>Escape character is '^]'. <br/>hello <br/>Wed Oct 17 23:23:36 EDT 2007 <br/>quit <br/>Connection closed by foreign host. <br/>user@myhost:~&gt;</td>
+<td>MINA Time server started. <br/>Message written...</td>
+</tr>
+</tbody>
+</table>
+<h2 id="whats-next">What's Next?</h2>
+<p>Please visit our Documentation page to find out more resources. You can also keep reading other tutorials.</p>
+
+
+    <div class="nav">
+        <div class="nav_prev">
+        
+            <a href="application-architecture.html">Application Architecture</a>
+		
+        </div>
+        <div class="nav_up">
+        
+            <a href="ch2-basics.html">Chapter 2 - Basics</a>
+		
+        </div>
+        <div class="nav_next">
+        
+            <a href="sample-tcp-client.html">Sample TCP Client</a>
+		
+        </div>
+        <div class="clearfix"></div>
+    </div>
+
+
+                </div><!-- rightColumn -->
+                <div id="endContent"></div>
+            </div><!-- content -->
+            <div id="footer">&copy; 2003-2012, <a href="http://www.apache.org">The Apache Software Foundation</a> - <a href="./../../../privacy-policy.html">Privacy Policy</a><br />
+                Apache MINA, MINA, Apache Vysper, Vysper, Apache SSHd, SSHd, Apache FtpServer, FtpServer, Apache AsyncWeb, AsyncWeb,
+                Apache, the Apache feather logo, and the Apache Mina project logos are trademarks of The Apache Software Foundation.
+            </div>
+        </div><!-- container -->
+    </body>
+</html>
+

Added: websites/staging/mina/trunk/content/mina-project/userguide/ch2-basics/sample-udp-client.html
==============================================================================
--- websites/staging/mina/trunk/content/mina-project/userguide/ch2-basics/sample-udp-client.html (added)
+++ websites/staging/mina/trunk/content/mina-project/userguide/ch2-basics/sample-udp-client.html Thu Nov 15 13:10:37 2012
@@ -0,0 +1,223 @@
+<!DOCTYPE html>
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You under the Apache License, Version 2.0
+    (the "License"); you may not use this file except in compliance with
+    the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<html>
+<head>
+	<title>Sample UDP Client &mdash; Apache MINA</title>
+	
+		<link href="./../../../css/common.css" rel="stylesheet" type="text/css">
+		<link href="./../../../css/mina.css" rel="stylesheet" type="text/css">
+	
+</head>
+  <body>
+    <div id="container">
+      <div id="header">
+        <div id="subProjectsNavBar">
+          <a href="./../../../">
+            
+              <strong>Apache MINA Project</strong>
+            
+          </a>
+          &nbsp;|&nbsp;
+          <a href="./../../../mina/index.html">
+            
+              MINA
+            
+          </a>
+          &nbsp;|&nbsp;
+          <a href="./../../../asyncweb/index.html">
+            
+              AsyncWeb
+            
+          </a>
+          &nbsp;|&nbsp;
+          <a href="./../../../ftpserver/index.html">
+            
+              FtpServer
+            
+          </a>
+          &nbsp;|&nbsp;
+          <a href="./../../../sshd/index.html">
+            
+              SSHD
+            
+          </a>
+          &nbsp;|&nbsp;
+          <a href="./../../../vysper/index.html">
+            
+              Vysper
+            
+          </a>
+        </div><!-- subProjectsNavBar -->
+      </div><!-- header -->
+      <div id="content">
+        <div id="leftColumn">
+                              
+          
+          
+          
+          
+          
+            <div id="navigation">
+
+    <h5>Latest Downloads</h5>
+    <ul>
+        <li><a href="./../../../downloads-mina.html">Mina 2.0.7</a></li>
+        <li><a href="./../../../downloads-ftpserver.html">FtpServer 1.0.6</a></li>
+        <li><a href="./../../../downloads-sshd.html">SSHD 0.8.0</a></li>
+        <li><a href="./../../../downloads-vysper.html">Vysper 0.7</a></li>
+    </ul>
+    <h5>Projects</h5>
+    <ul>
+        <li><a href="./../../../mina/index.html">MINA</a></li>
+        <li><a href="./../../../asyncweb/index.html">AsyncWeb</a></li>
+        <li><a href="./../../../ftpserver/index.html">FtpServer</a></li>
+        <li><a href="./../../../sshd/index.html">SSHD</a></li>
+        <li><a href="./../../../vysper/index.html">Vysper</a></li>
+    </ul>
+
+    <h5>Community</h5>
+    <ul>
+      <li><a href="./../../../contributors.html" class="external-link" rel="nofollow">Team</a></li>
+      <li><a href="http://www.apache.org/licenses/" class="external-link" rel="nofollow">License</a></li>
+      <li><a href="http://www.apache.org/foundation/contributing.html" class="external-link" rel="nofollow">Contributing</a></li>
+      <li><a href="http://www.apache.org/" title="Apache Software Foundation" class="external-link" rel="nofollow">ASF main site</a></li>
+      <li><a href="http://www.apache.org/foundation/thanks.html" class="external-link" rel="nofollow">Thanks</a></li>
+      <li><a href="http://www.apache.org/foundation/sponsorship.html" title="The ASF sponsorship program" class="external-link" rel="nofollow">Sponsorship program</a></li>
+      <li><a href="http://www.apache.org/security/" class="external-link" rel="nofollow">Security</a></li>
+    </ul>
+
+    <h3><a name="Navigation-Upcoming"></a>Upcoming</h3>
+
+</div>
+
+<!-- navigation -->
+          
+        </div><!-- leftColumn -->
+      <div id="rightColumn">
+
+
+
+    <div class="nav">
+        <div class="nav_prev">
+        
+            <a href="sample-udp-server.html">Sample UDP Server</a>
+		
+        </div>
+        <div class="nav_up">
+        
+            <a href="ch2-basics.html">Chapter 2 - Basics</a>
+		
+        </div>
+        <div class="nav_next">
+        
+            <a href="summary.html">Summary</a>
+		
+        </div>
+        <div class="clearfix"></div>
+    </div>
+
+
+<h1 id="sample-udp-client">Sample UDP Client</h1>
+<p>Lets look at the client code for the UDP Server from previous section.</p>
+<p>To implement the Client we need to do following:</p>
+<ul>
+<li>Create Socket and Connect to Server</li>
+<li>Set the IoHandler</li>
+<li>Collect free memory</li>
+<li>Send the Data to the Server</li>
+</ul>
+<p>We will begin by looking at the file <a href="http://mina.apache.org/report/trunk/xref/org/apache/mina/example/udp/client/MemMonClient.html">MemMonClient.java</a>, found in the org.apache.mina.example.udp.client java package. The first few lines of the code are simple and straightforward.</p>
+<div class="codehilite"><pre><span class="n">connector</span> <span class="o">=</span> <span class="k">new</span> <span class="n">NioDatagramConnector</span><span class="o">();</span>
+<span class="n">connector</span><span class="o">.</span><span class="na">setHandler</span><span class="o">(</span> <span class="k">this</span> <span class="o">);</span>
+<span class="n">ConnectFuture</span> <span class="n">connFuture</span> <span class="o">=</span> <span class="n">connector</span><span class="o">.</span><span class="na">connect</span><span class="o">(</span> <span class="k">new</span> <span class="n">InetSocketAddress</span><span class="o">(</span><span class="s">&quot;localhost&quot;</span><span class="o">,</span> <span class="n">MemoryMonitor</span><span class="o">.</span><span class="na">PORT</span> <span class="o">));</span>
+</pre></div>
+
+
+<p>Here we create a NioDatagramConnector, set the handler and connect to the server. One gotcha I ran into was that you must set the host in the InetSocketAddress object or else nothing seems to work. This example was mostly written and tested on a Windows XP machine, so things may be different elsewhere. Next we will wait for acknowledgment that the client has connected to the server. Once we know we are connected, we can start writing data to the server. Here is that code:</p>
+<div class="codehilite"><pre><span class="n">connFuture</span><span class="o">.</span><span class="na">addListener</span><span class="o">(</span> <span class="k">new</span> <span class="n">IoFutureListener</span><span class="o">(){</span>
+            <span class="kd">public</span> <span class="kt">void</span> <span class="nf">operationComplete</span><span class="o">(</span><span class="n">IoFuture</span> <span class="n">future</span><span class="o">)</span> <span class="o">{</span>
+                <span class="n">ConnectFuture</span> <span class="n">connFuture</span> <span class="o">=</span> <span class="o">(</span><span class="n">ConnectFuture</span><span class="o">)</span><span class="n">future</span><span class="o">;</span>
+                <span class="k">if</span><span class="o">(</span> <span class="n">connFuture</span><span class="o">.</span><span class="na">isConnected</span><span class="o">()</span> <span class="o">){</span>
+                    <span class="n">session</span> <span class="o">=</span> <span class="n">future</span><span class="o">.</span><span class="na">getSession</span><span class="o">();</span>
+                    <span class="k">try</span> <span class="o">{</span>
+                        <span class="n">sendData</span><span class="o">();</span>
+                    <span class="o">}</span> <span class="k">catch</span> <span class="o">(</span><span class="n">InterruptedException</span> <span class="n">e</span><span class="o">)</span> <span class="o">{</span>
+                        <span class="n">e</span><span class="o">.</span><span class="na">printStackTrace</span><span class="o">();</span>
+                    <span class="o">}</span>
+                <span class="o">}</span> <span class="k">else</span> <span class="o">{</span>
+                    <span class="n">log</span><span class="o">.</span><span class="na">error</span><span class="o">(</span><span class="s">&quot;Not connected...exiting&quot;</span><span class="o">);</span>
+                <span class="o">}</span>
+            <span class="o">}</span>
+        <span class="o">});</span>
+</pre></div>
+
+
+<p>Here we add a listener to the ConnectFuture object and when we receive a callback that the client has connected, we will start to write data. The writing of data to the server will be handled by a method called sendData. This method is shown below:</p>
+<div class="codehilite"><pre><span class="kd">private</span> <span class="kt">void</span> <span class="nf">sendData</span><span class="o">()</span> <span class="kd">throws</span> <span class="n">InterruptedException</span> <span class="o">{</span>
+    <span class="k">for</span> <span class="o">(</span><span class="kt">int</span> <span class="n">i</span> <span class="o">=</span> <span class="mi">0</span><span class="o">;</span> <span class="n">i</span> <span class="o">&lt;</span> <span class="mi">30</span><span class="o">;</span> <span class="n">i</span><span class="o">++)</span> <span class="o">{</span>
+        <span class="kt">long</span> <span class="n">free</span> <span class="o">=</span> <span class="n">Runtime</span><span class="o">.</span><span class="na">getRuntime</span><span class="o">().</span><span class="na">freeMemory</span><span class="o">();</span>
+        <span class="n">IoBuffer</span> <span class="n">buffer</span> <span class="o">=</span> <span class="n">IoBuffer</span><span class="o">.</span><span class="na">allocate</span><span class="o">(</span><span class="mi">8</span><span class="o">);</span>
+        <span class="n">buffer</span><span class="o">.</span><span class="na">putLong</span><span class="o">(</span><span class="n">free</span><span class="o">);</span>
+        <span class="n">buffer</span><span class="o">.</span><span class="na">flip</span><span class="o">();</span>
+        <span class="n">session</span><span class="o">.</span><span class="na">write</span><span class="o">(</span><span class="n">buffer</span><span class="o">);</span>
+        <span class="k">try</span> <span class="o">{</span>
+            <span class="n">Thread</span><span class="o">.</span><span class="na">sleep</span><span class="o">(</span><span class="mi">1000</span><span class="o">);</span>
+        <span class="o">}</span> <span class="k">catch</span> <span class="o">(</span><span class="n">InterruptedException</span> <span class="n">e</span><span class="o">)</span> <span class="o">{</span>
+            <span class="n">e</span><span class="o">.</span><span class="na">printStackTrace</span><span class="o">();</span>
+            <span class="k">throw</span> <span class="k">new</span> <span class="nf">InterruptedException</span><span class="o">(</span><span class="n">e</span><span class="o">.</span><span class="na">getMessage</span><span class="o">());</span>
+        <span class="o">}</span>
+    <span class="o">}</span>
+<span class="o">}</span>
+</pre></div>
+
+
+<p>This method will write the amount of free memory to the server once a second for 30 seconds. Here you can see that we allocate a IoBuffer large enough to hold a long variable and then place the amount of free memory in the buffer. This buffer is then flipped and written to the server.</p>
+<p>Our UDP Client implementation is complete.</p>
+
+
+    <div class="nav">
+        <div class="nav_prev">
+        
+            <a href="sample-udp-server.html">Sample UDP Server</a>
+		
+        </div>
+        <div class="nav_up">
+        
+            <a href="ch2-basics.html">Chapter 2 - Basics</a>
+		
+        </div>
+        <div class="nav_next">
+        
+            <a href="summary.html">Summary</a>
+		
+        </div>
+        <div class="clearfix"></div>
+    </div>
+
+
+                </div><!-- rightColumn -->
+                <div id="endContent"></div>
+            </div><!-- content -->
+            <div id="footer">&copy; 2003-2012, <a href="http://www.apache.org">The Apache Software Foundation</a> - <a href="./../../../privacy-policy.html">Privacy Policy</a><br />
+                Apache MINA, MINA, Apache Vysper, Vysper, Apache SSHd, SSHd, Apache FtpServer, FtpServer, Apache AsyncWeb, AsyncWeb,
+                Apache, the Apache feather logo, and the Apache Mina project logos are trademarks of The Apache Software Foundation.
+            </div>
+        </div><!-- container -->
+    </body>
+</html>
+

Added: websites/staging/mina/trunk/content/mina-project/userguide/ch2-basics/sample-udp-server.html
==============================================================================
--- websites/staging/mina/trunk/content/mina-project/userguide/ch2-basics/sample-udp-server.html (added)
+++ websites/staging/mina/trunk/content/mina-project/userguide/ch2-basics/sample-udp-server.html Thu Nov 15 13:10:37 2012
@@ -0,0 +1,235 @@
+<!DOCTYPE html>
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You under the Apache License, Version 2.0
+    (the "License"); you may not use this file except in compliance with
+    the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<html>
+<head>
+	<title>Sample UDP Server &mdash; Apache MINA</title>
+	
+		<link href="./../../../css/common.css" rel="stylesheet" type="text/css">
+		<link href="./../../../css/mina.css" rel="stylesheet" type="text/css">
+	
+</head>
+  <body>
+    <div id="container">
+      <div id="header">
+        <div id="subProjectsNavBar">
+          <a href="./../../../">
+            
+              <strong>Apache MINA Project</strong>
+            
+          </a>
+          &nbsp;|&nbsp;
+          <a href="./../../../mina/index.html">
+            
+              MINA
+            
+          </a>
+          &nbsp;|&nbsp;
+          <a href="./../../../asyncweb/index.html">
+            
+              AsyncWeb
+            
+          </a>
+          &nbsp;|&nbsp;
+          <a href="./../../../ftpserver/index.html">
+            
+              FtpServer
+            
+          </a>
+          &nbsp;|&nbsp;
+          <a href="./../../../sshd/index.html">
+            
+              SSHD
+            
+          </a>
+          &nbsp;|&nbsp;
+          <a href="./../../../vysper/index.html">
+            
+              Vysper
+            
+          </a>
+        </div><!-- subProjectsNavBar -->
+      </div><!-- header -->
+      <div id="content">
+        <div id="leftColumn">
+                              
+          
+          
+          
+          
+          
+            <div id="navigation">
+
+    <h5>Latest Downloads</h5>
+    <ul>
+        <li><a href="./../../../downloads-mina.html">Mina 2.0.7</a></li>
+        <li><a href="./../../../downloads-ftpserver.html">FtpServer 1.0.6</a></li>
+        <li><a href="./../../../downloads-sshd.html">SSHD 0.8.0</a></li>
+        <li><a href="./../../../downloads-vysper.html">Vysper 0.7</a></li>
+    </ul>
+    <h5>Projects</h5>
+    <ul>
+        <li><a href="./../../../mina/index.html">MINA</a></li>
+        <li><a href="./../../../asyncweb/index.html">AsyncWeb</a></li>
+        <li><a href="./../../../ftpserver/index.html">FtpServer</a></li>
+        <li><a href="./../../../sshd/index.html">SSHD</a></li>
+        <li><a href="./../../../vysper/index.html">Vysper</a></li>
+    </ul>
+
+    <h5>Community</h5>
+    <ul>
+      <li><a href="./../../../contributors.html" class="external-link" rel="nofollow">Team</a></li>
+      <li><a href="http://www.apache.org/licenses/" class="external-link" rel="nofollow">License</a></li>
+      <li><a href="http://www.apache.org/foundation/contributing.html" class="external-link" rel="nofollow">Contributing</a></li>
+      <li><a href="http://www.apache.org/" title="Apache Software Foundation" class="external-link" rel="nofollow">ASF main site</a></li>
+      <li><a href="http://www.apache.org/foundation/thanks.html" class="external-link" rel="nofollow">Thanks</a></li>
+      <li><a href="http://www.apache.org/foundation/sponsorship.html" title="The ASF sponsorship program" class="external-link" rel="nofollow">Sponsorship program</a></li>
+      <li><a href="http://www.apache.org/security/" class="external-link" rel="nofollow">Security</a></li>
+    </ul>
+
+    <h3><a name="Navigation-Upcoming"></a>Upcoming</h3>
+
+</div>
+
+<!-- navigation -->
+          
+        </div><!-- leftColumn -->
+      <div id="rightColumn">
+
+
+
+    <div class="nav">
+        <div class="nav_prev">
+        
+            <a href="sample-tcp-client.html">Sample TCP-CLient</a>
+		
+        </div>
+        <div class="nav_up">
+        
+            <a href="ch2-basics.html">Chapter 2 - Basics</a>
+		
+        </div>
+        <div class="nav_next">
+        
+            <a href="sample-udp-client.html">Sample UDP Client</a>
+		
+        </div>
+        <div class="clearfix"></div>
+    </div>
+
+
+<h1 id="sample-udp-server">Sample UDP Server</h1>
+<p>We will begin by looking at the code found in the <a href="http://mina.apache.org/report/trunk/xref/org/apache/mina/example/udp/package-summary.html">org.apache.mina.example.udp</a> package. To keep life simple, we shall concentrate on MINA related constructs only.</p>
+<p>To construct the server, we shall have to do the following:</p>
+<ol>
+<li>Create a Datagram Socket to listen for incoming Client requests (See <a href="http://mina.apache.org/report/trunk/xref/org/apache/mina/example/udp/MemoryMonitor.html">MemoryMonitor.java</a>)</li>
+<li>Create an IoHandler to handle the MINA framework generated events (See <a href="http://mina.apache.org/report/trunk/xref/org/apache/mina/example/udp/MemoryMonitorHandler.html">MemoryMonitorHandler.java</a>)</li>
+</ol>
+<p>Here is the first snippet that addresses Point# 1:</p>
+<div class="codehilite"><pre><span class="n">NioDatagramAcceptor</span> <span class="n">acceptor</span> <span class="o">=</span> <span class="k">new</span> <span class="n">NioDatagramAcceptor</span><span class="o">();</span>
+<span class="n">acceptor</span><span class="o">.</span><span class="na">setHandler</span><span class="o">(</span><span class="k">new</span> <span class="n">MemoryMonitorHandler</span><span class="o">(</span><span class="k">this</span><span class="o">));</span>
+</pre></div>
+
+
+<p>Here, we create a NioDatagramAcceptor to listen for incoming Client requests, and set the IoHandler.The variable 'PORT' is just an int. The next step is to add a logging filter to the filter chain that this DatagramAcceptor will use. LoggingFilter is a very nice way to see MINA in Action. It generate log statements at various stages, providing an insight into how MINA works.</p>
+<div class="codehilite"><pre><span class="n">DefaultIoFilterChainBuilder</span> <span class="n">chain</span> <span class="o">=</span> <span class="n">acceptor</span><span class="o">.</span><span class="na">getFilterChain</span><span class="o">();</span>
+<span class="n">chain</span><span class="o">.</span><span class="na">addLast</span><span class="o">(</span><span class="s">&quot;logger&quot;</span><span class="o">,</span> <span class="k">new</span> <span class="n">LoggingFilter</span><span class="o">());</span>
+</pre></div>
+
+
+<p>Next we get into some more specific code for the UDP traffic. We will set the acceptor to reuse the address</p>
+<div class="codehilite"><pre><span class="n">DatagramSessionConfig</span> <span class="n">dcfg</span> <span class="o">=</span> <span class="n">acceptor</span><span class="o">.</span><span class="na">getSessionConfig</span><span class="o">();</span>
+<span class="n">dcfg</span><span class="o">.</span><span class="na">setReuseAddress</span><span class="o">(</span><span class="kc">true</span><span class="o">);</span><span class="n">acceptor</span><span class="o">.</span><span class="na">bind</span><span class="o">(</span><span class="k">new</span> <span class="n">InetSocketAddress</span><span class="o">(</span><span class="n">PORT</span><span class="o">));</span>
+</pre></div>
+
+
+<p>Of course the last thing that is required here is to call bind().</p>
+<h2 id="iohandler-implementation">IoHandler implementation</h2>
+<p>There are three major events of interest for our Server Implementation</p>
+<ul>
+<li>Session Created</li>
+<li>Message Received</li>
+<li>Session Closed</li>
+</ul>
+<p>Lets look at each of them in detail</p>
+<h3 id="session-created-event">Session Created Event</h3>
+<div class="codehilite"><pre><span class="nd">@Override</span>
+<span class="kd">public</span> <span class="kt">void</span> <span class="nf">sessionCreated</span><span class="o">(</span><span class="n">IoSession</span> <span class="n">session</span><span class="o">)</span> <span class="kd">throws</span> <span class="n">Exception</span> <span class="o">{</span>
+    <span class="n">SocketAddress</span> <span class="n">remoteAddress</span> <span class="o">=</span> <span class="n">session</span><span class="o">.</span><span class="na">getRemoteAddress</span><span class="o">();</span>
+    <span class="n">server</span><span class="o">.</span><span class="na">addClient</span><span class="o">(</span><span class="n">remoteAddress</span><span class="o">);</span>
+<span class="o">}</span>
+</pre></div>
+
+
+<p>In the session creation event, we just call addClient() function, which internally adds a Tab to the UI</p>
+<h3 id="message-received-event">Message Received Event</h3>
+<div class="codehilite"><pre><span class="nd">@Override</span>
+<span class="kd">public</span> <span class="kt">void</span> <span class="nf">messageReceived</span><span class="o">(</span><span class="n">IoSession</span> <span class="n">session</span><span class="o">,</span> <span class="n">Object</span> <span class="n">message</span><span class="o">)</span> <span class="kd">throws</span> <span class="n">Exception</span> <span class="o">{</span>
+    <span class="k">if</span> <span class="o">(</span><span class="n">message</span> <span class="k">instanceof</span> <span class="n">IoBuffer</span><span class="o">)</span> <span class="o">{</span>
+        <span class="n">IoBuffer</span> <span class="n">buffer</span> <span class="o">=</span> <span class="o">(</span><span class="n">IoBuffer</span><span class="o">)</span> <span class="n">message</span><span class="o">;</span>
+        <span class="n">SocketAddress</span> <span class="n">remoteAddress</span> <span class="o">=</span> <span class="n">session</span><span class="o">.</span><span class="na">getRemoteAddress</span><span class="o">();</span>
+        <span class="n">server</span><span class="o">.</span><span class="na">recvUpdate</span><span class="o">(</span><span class="n">remoteAddress</span><span class="o">,</span> <span class="n">buffer</span><span class="o">.</span><span class="na">getLong</span><span class="o">());</span>
+    <span class="o">}</span>
+ <span class="o">}</span>
+</pre></div>
+
+
+<p>In the message received event, we just dump the data received in the message. Applications that need to send responses, can process message and write the responses onto session in this function.</p>
+<h3 id="session-closed-event">Session Closed Event</h3>
+<div class="codehilite"><pre><span class="nd">@Override</span>
+<span class="kd">public</span> <span class="kt">void</span> <span class="nf">sessionClosed</span><span class="o">(</span><span class="n">IoSession</span> <span class="n">session</span><span class="o">)</span> <span class="kd">throws</span> <span class="n">Exception</span> <span class="o">{</span>
+    <span class="n">System</span><span class="o">.</span><span class="na">out</span><span class="o">.</span><span class="na">println</span><span class="o">(</span><span class="s">&quot;Session closed...&quot;</span><span class="o">);</span>
+    <span class="n">SocketAddress</span> <span class="n">remoteAddress</span> <span class="o">=</span> <span class="n">session</span><span class="o">.</span><span class="na">getRemoteAddress</span><span class="o">();</span>
+    <span class="n">server</span><span class="o">.</span><span class="na">removeClient</span><span class="o">(</span><span class="n">remoteAddress</span><span class="o">);</span>
+<span class="o">}</span>
+</pre></div>
+
+
+<p>In the Session Closed, event we just remove the Client tab from the UI</p>
+
+
+    <div class="nav">
+        <div class="nav_prev">
+        
+            <a href="sample-tcp-client.html">Sample TCP-CLient</a>
+		
+        </div>
+        <div class="nav_up">
+        
+            <a href="ch2-basics.html">Chapter 2 - Basics</a>
+		
+        </div>
+        <div class="nav_next">
+        
+            <a href="sample-udp-client.html">Sample UDP Client</a>
+		
+        </div>
+        <div class="clearfix"></div>
+    </div>
+
+
+                </div><!-- rightColumn -->
+                <div id="endContent"></div>
+            </div><!-- content -->
+            <div id="footer">&copy; 2003-2012, <a href="http://www.apache.org">The Apache Software Foundation</a> - <a href="./../../../privacy-policy.html">Privacy Policy</a><br />
+                Apache MINA, MINA, Apache Vysper, Vysper, Apache SSHd, SSHd, Apache FtpServer, FtpServer, Apache AsyncWeb, AsyncWeb,
+                Apache, the Apache feather logo, and the Apache Mina project logos are trademarks of The Apache Software Foundation.
+            </div>
+        </div><!-- container -->
+    </body>
+</html>
+

Added: websites/staging/mina/trunk/content/mina-project/userguide/ch2-basics/server-architecture.html
==============================================================================
--- websites/staging/mina/trunk/content/mina-project/userguide/ch2-basics/server-architecture.html (added)
+++ websites/staging/mina/trunk/content/mina-project/userguide/ch2-basics/server-architecture.html Thu Nov 15 13:10:37 2012
@@ -0,0 +1,182 @@
+<!DOCTYPE html>
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You under the Apache License, Version 2.0
+    (the "License"); you may not use this file except in compliance with
+    the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<html>
+<head>
+	<title>Server Architecture &mdash; Apache MINA</title>
+	
+		<link href="./../../../css/common.css" rel="stylesheet" type="text/css">
+		<link href="./../../../css/mina.css" rel="stylesheet" type="text/css">
+	
+</head>
+  <body>
+    <div id="container">
+      <div id="header">
+        <div id="subProjectsNavBar">
+          <a href="./../../../">
+            
+              <strong>Apache MINA Project</strong>
+            
+          </a>
+          &nbsp;|&nbsp;
+          <a href="./../../../mina/index.html">
+            
+              MINA
+            
+          </a>
+          &nbsp;|&nbsp;
+          <a href="./../../../asyncweb/index.html">
+            
+              AsyncWeb
+            
+          </a>
+          &nbsp;|&nbsp;
+          <a href="./../../../ftpserver/index.html">
+            
+              FtpServer
+            
+          </a>
+          &nbsp;|&nbsp;
+          <a href="./../../../sshd/index.html">
+            
+              SSHD
+            
+          </a>
+          &nbsp;|&nbsp;
+          <a href="./../../../vysper/index.html">
+            
+              Vysper
+            
+          </a>
+        </div><!-- subProjectsNavBar -->
+      </div><!-- header -->
+      <div id="content">
+        <div id="leftColumn">
+                              
+          
+          
+          
+          
+          
+            <div id="navigation">
+
+    <h5>Latest Downloads</h5>
+    <ul>
+        <li><a href="./../../../downloads-mina.html">Mina 2.0.7</a></li>
+        <li><a href="./../../../downloads-ftpserver.html">FtpServer 1.0.6</a></li>
+        <li><a href="./../../../downloads-sshd.html">SSHD 0.8.0</a></li>
+        <li><a href="./../../../downloads-vysper.html">Vysper 0.7</a></li>
+    </ul>
+    <h5>Projects</h5>
+    <ul>
+        <li><a href="./../../../mina/index.html">MINA</a></li>
+        <li><a href="./../../../asyncweb/index.html">AsyncWeb</a></li>
+        <li><a href="./../../../ftpserver/index.html">FtpServer</a></li>
+        <li><a href="./../../../sshd/index.html">SSHD</a></li>
+        <li><a href="./../../../vysper/index.html">Vysper</a></li>
+    </ul>
+
+    <h5>Community</h5>
+    <ul>
+      <li><a href="./../../../contributors.html" class="external-link" rel="nofollow">Team</a></li>
+      <li><a href="http://www.apache.org/licenses/" class="external-link" rel="nofollow">License</a></li>
+      <li><a href="http://www.apache.org/foundation/contributing.html" class="external-link" rel="nofollow">Contributing</a></li>
+      <li><a href="http://www.apache.org/" title="Apache Software Foundation" class="external-link" rel="nofollow">ASF main site</a></li>
+      <li><a href="http://www.apache.org/foundation/thanks.html" class="external-link" rel="nofollow">Thanks</a></li>
+      <li><a href="http://www.apache.org/foundation/sponsorship.html" title="The ASF sponsorship program" class="external-link" rel="nofollow">Sponsorship program</a></li>
+      <li><a href="http://www.apache.org/security/" class="external-link" rel="nofollow">Security</a></li>
+    </ul>
+
+    <h3><a name="Navigation-Upcoming"></a>Upcoming</h3>
+
+</div>
+
+<!-- navigation -->
+          
+        </div><!-- leftColumn -->
+      <div id="rightColumn">
+
+
+
+    <div class="nav">
+        <div class="nav_prev">
+        
+			&nbsp;
+        
+        </div>
+        <div class="nav_up">
+        
+            <a href="application-architecture.html">Application Architecture</a>
+		
+        </div>
+        <div class="nav_next">
+        
+            <a href="client-architecture.html">Client Architecture</a>
+		
+        </div>
+        <div class="clearfix"></div>
+    </div>
+
+
+<h1 id="server-architecture">Server Architecture</h1>
+<p>We have exposed the <strong>MINA</strong> Application Architecture in the previous section. Let's now focus on the Server Architecture. Basically, a Server listens on a port for incoming requests, process them and send replies. It also creates and handles a session for each client (whenever we have a TCP or UDP based protocol), this will be explain more extensively in the <a href="../ch4/ch4.html">chapter 4</a>.</p>
+<p><img alt="" src="../../../staticresources/images/mina/Server_arch.png" /></p>
+<ul>
+<li>IOAcceptor listens on the network for incoming connections/packets</li>
+<li>For a new connection, a new session is created and all subsequent request from IP Address/Port combination are handled in that Session</li>
+<li>All packets received for a Session, traverses the Filter Chain as specified in the diagram. Filters can be used to modify the content of packets (like converting to Objects, adding/removing information etc). For converting to/from raw bytes to High Level Objects, PacketEncoder/Decoder are particularly useful</li>
+<li>Finally the packet or converted object lands in <code>IOHandler</code>. <code>IOHandler</code>s can be used to fulfill business needs.</li>
+</ul>
+<h2 id="session-creation">Session creation</h2>
+<p>Whenever a client connects on a MINA server, we will create a new session to store persistent data into it. Even if the protocol is not connected, this session will be created. The following schema shows how <strong>MINA</strong> handles incoming connections :</p>
+<p><img alt="Incoming connections handling" src="../../../staticresources/images/mina/incoming-connections.png" /></p>
+<h2 id="incoming-messages-processing">Incoming messages processing</h2>
+<p>We will now explain how <strong>MINA</strong> processes incoming messages.</p>
+<p>Assuming that a session has been created, any new incoming message will result in a selector being waken up</p>
+
+
+    <div class="nav">
+        <div class="nav_prev">
+        
+			&nbsp;
+        
+        </div>
+        <div class="nav_up">
+        
+            <a href="application-architecture.html">Application Architecture</a>
+		
+        </div>
+        <div class="nav_next">
+        
+            <a href="client-architecture.html">Client Architecture</a>
+		
+        </div>
+        <div class="clearfix"></div>
+    </div>
+
+
+                </div><!-- rightColumn -->
+                <div id="endContent"></div>
+            </div><!-- content -->
+            <div id="footer">&copy; 2003-2012, <a href="http://www.apache.org">The Apache Software Foundation</a> - <a href="./../../../privacy-policy.html">Privacy Policy</a><br />
+                Apache MINA, MINA, Apache Vysper, Vysper, Apache SSHd, SSHd, Apache FtpServer, FtpServer, Apache AsyncWeb, AsyncWeb,
+                Apache, the Apache feather logo, and the Apache Mina project logos are trademarks of The Apache Software Foundation.
+            </div>
+        </div><!-- container -->
+    </body>
+</html>
+

Added: websites/staging/mina/trunk/content/mina-project/userguide/ch2-basics/summary.html
==============================================================================
--- websites/staging/mina/trunk/content/mina-project/userguide/ch2-basics/summary.html (added)
+++ websites/staging/mina/trunk/content/mina-project/userguide/ch2-basics/summary.html Thu Nov 15 13:10:37 2012
@@ -0,0 +1,170 @@
+<!DOCTYPE html>
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You under the Apache License, Version 2.0
+    (the "License"); you may not use this file except in compliance with
+    the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<html>
+<head>
+	<title>Summary &mdash; Apache MINA</title>
+	
+		<link href="./../../../css/common.css" rel="stylesheet" type="text/css">
+		<link href="./../../../css/mina.css" rel="stylesheet" type="text/css">
+	
+</head>
+  <body>
+    <div id="container">
+      <div id="header">
+        <div id="subProjectsNavBar">
+          <a href="./../../../">
+            
+              <strong>Apache MINA Project</strong>
+            
+          </a>
+          &nbsp;|&nbsp;
+          <a href="./../../../mina/index.html">
+            
+              MINA
+            
+          </a>
+          &nbsp;|&nbsp;
+          <a href="./../../../asyncweb/index.html">
+            
+              AsyncWeb
+            
+          </a>
+          &nbsp;|&nbsp;
+          <a href="./../../../ftpserver/index.html">
+            
+              FtpServer
+            
+          </a>
+          &nbsp;|&nbsp;
+          <a href="./../../../sshd/index.html">
+            
+              SSHD
+            
+          </a>
+          &nbsp;|&nbsp;
+          <a href="./../../../vysper/index.html">
+            
+              Vysper
+            
+          </a>
+        </div><!-- subProjectsNavBar -->
+      </div><!-- header -->
+      <div id="content">
+        <div id="leftColumn">
+                              
+          
+          
+          
+          
+          
+            <div id="navigation">
+
+    <h5>Latest Downloads</h5>
+    <ul>
+        <li><a href="./../../../downloads-mina.html">Mina 2.0.7</a></li>
+        <li><a href="./../../../downloads-ftpserver.html">FtpServer 1.0.6</a></li>
+        <li><a href="./../../../downloads-sshd.html">SSHD 0.8.0</a></li>
+        <li><a href="./../../../downloads-vysper.html">Vysper 0.7</a></li>
+    </ul>
+    <h5>Projects</h5>
+    <ul>
+        <li><a href="./../../../mina/index.html">MINA</a></li>
+        <li><a href="./../../../asyncweb/index.html">AsyncWeb</a></li>
+        <li><a href="./../../../ftpserver/index.html">FtpServer</a></li>
+        <li><a href="./../../../sshd/index.html">SSHD</a></li>
+        <li><a href="./../../../vysper/index.html">Vysper</a></li>
+    </ul>
+
+    <h5>Community</h5>
+    <ul>
+      <li><a href="./../../../contributors.html" class="external-link" rel="nofollow">Team</a></li>
+      <li><a href="http://www.apache.org/licenses/" class="external-link" rel="nofollow">License</a></li>
+      <li><a href="http://www.apache.org/foundation/contributing.html" class="external-link" rel="nofollow">Contributing</a></li>
+      <li><a href="http://www.apache.org/" title="Apache Software Foundation" class="external-link" rel="nofollow">ASF main site</a></li>
+      <li><a href="http://www.apache.org/foundation/thanks.html" class="external-link" rel="nofollow">Thanks</a></li>
+      <li><a href="http://www.apache.org/foundation/sponsorship.html" title="The ASF sponsorship program" class="external-link" rel="nofollow">Sponsorship program</a></li>
+      <li><a href="http://www.apache.org/security/" class="external-link" rel="nofollow">Security</a></li>
+    </ul>
+
+    <h3><a name="Navigation-Upcoming"></a>Upcoming</h3>
+
+</div>
+
+<!-- navigation -->
+          
+        </div><!-- leftColumn -->
+      <div id="rightColumn">
+
+
+
+    <div class="nav">
+        <div class="nav_prev">
+        
+            <a href="sample-udp-client.html">Sample UDP client</a>
+		
+        </div>
+        <div class="nav_up">
+        
+            <a href="ch2-basics.html">Chapter 2 - Basics</a>
+		
+        </div>
+        <div class="nav_next">
+        
+			&nbsp;
+        
+        </div>
+        <div class="clearfix"></div>
+    </div>
+
+
+<h1 id="summary">Summary</h1>
+<p>In this chapter, we looked at MINA based Application Architecture, for Client as well as Server. We also touched upon the implementation of Sample TCP Server/Client, and UDP Server and Client.</p>
+<p>In the chapters to come we shall discuss about MINA Core constructs and advanced topics</p>
+
+
+    <div class="nav">
+        <div class="nav_prev">
+        
+            <a href="sample-udp-client.html">Sample UDP client</a>
+		
+        </div>
+        <div class="nav_up">
+        
+            <a href="ch2-basics.html">Chapter 2 - Basics</a>
+		
+        </div>
+        <div class="nav_next">
+        
+			&nbsp;
+        
+        </div>
+        <div class="clearfix"></div>
+    </div>
+
+
+                </div><!-- rightColumn -->
+                <div id="endContent"></div>
+            </div><!-- content -->
+            <div id="footer">&copy; 2003-2012, <a href="http://www.apache.org">The Apache Software Foundation</a> - <a href="./../../../privacy-policy.html">Privacy Policy</a><br />
+                Apache MINA, MINA, Apache Vysper, Vysper, Apache SSHd, SSHd, Apache FtpServer, FtpServer, Apache AsyncWeb, AsyncWeb,
+                Apache, the Apache feather logo, and the Apache Mina project logos are trademarks of The Apache Software Foundation.
+            </div>
+        </div><!-- container -->
+    </body>
+</html>
+

Added: websites/staging/mina/trunk/content/mina-project/userguide/ch3-service/acceptor.html
==============================================================================
--- websites/staging/mina/trunk/content/mina-project/userguide/ch3-service/acceptor.html (added)
+++ websites/staging/mina/trunk/content/mina-project/userguide/ch3-service/acceptor.html Thu Nov 15 13:10:37 2012
@@ -0,0 +1,249 @@
+<!DOCTYPE html>
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one or more
+    contributor license agreements.  See the NOTICE file distributed with
+    this work for additional information regarding copyright ownership.
+    The ASF licenses this file to You under the Apache License, Version 2.0
+    (the "License"); you may not use this file except in compliance with
+    the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+    See the License for the specific language governing permissions and
+    limitations under the License.
+-->
+<html>
+<head>
+	<title>Chapter 8 - Acceptor &mdash; Apache MINA</title>
+	
+		<link href="./../../../css/common.css" rel="stylesheet" type="text/css">
+		<link href="./../../../css/mina.css" rel="stylesheet" type="text/css">
+	
+</head>
+  <body>
+    <div id="container">
+      <div id="header">
+        <div id="subProjectsNavBar">
+          <a href="./../../../">
+            
+              <strong>Apache MINA Project</strong>
+            
+          </a>
+          &nbsp;|&nbsp;
+          <a href="./../../../mina/index.html">
+            
+              MINA
+            
+          </a>
+          &nbsp;|&nbsp;
+          <a href="./../../../asyncweb/index.html">
+            
+              AsyncWeb
+            
+          </a>
+          &nbsp;|&nbsp;
+          <a href="./../../../ftpserver/index.html">
+            
+              FtpServer
+            
+          </a>
+          &nbsp;|&nbsp;
+          <a href="./../../../sshd/index.html">
+            
+              SSHD
+            
+          </a>
+          &nbsp;|&nbsp;
+          <a href="./../../../vysper/index.html">
+            
+              Vysper
+            
+          </a>
+        </div><!-- subProjectsNavBar -->
+      </div><!-- header -->
+      <div id="content">
+        <div id="leftColumn">
+                              
+          
+          
+          
+          
+          
+            <div id="navigation">
+
+    <h5>Latest Downloads</h5>
+    <ul>
+        <li><a href="./../../../downloads-mina.html">Mina 2.0.7</a></li>
+        <li><a href="./../../../downloads-ftpserver.html">FtpServer 1.0.6</a></li>
+        <li><a href="./../../../downloads-sshd.html">SSHD 0.8.0</a></li>
+        <li><a href="./../../../downloads-vysper.html">Vysper 0.7</a></li>
+    </ul>
+    <h5>Projects</h5>
+    <ul>
+        <li><a href="./../../../mina/index.html">MINA</a></li>
+        <li><a href="./../../../asyncweb/index.html">AsyncWeb</a></li>
+        <li><a href="./../../../ftpserver/index.html">FtpServer</a></li>
+        <li><a href="./../../../sshd/index.html">SSHD</a></li>
+        <li><a href="./../../../vysper/index.html">Vysper</a></li>
+    </ul>
+
+    <h5>Community</h5>
+    <ul>
+      <li><a href="./../../../contributors.html" class="external-link" rel="nofollow">Team</a></li>
+      <li><a href="http://www.apache.org/licenses/" class="external-link" rel="nofollow">License</a></li>
+      <li><a href="http://www.apache.org/foundation/contributing.html" class="external-link" rel="nofollow">Contributing</a></li>
+      <li><a href="http://www.apache.org/" title="Apache Software Foundation" class="external-link" rel="nofollow">ASF main site</a></li>
+      <li><a href="http://www.apache.org/foundation/thanks.html" class="external-link" rel="nofollow">Thanks</a></li>
+      <li><a href="http://www.apache.org/foundation/sponsorship.html" title="The ASF sponsorship program" class="external-link" rel="nofollow">Sponsorship program</a></li>
+      <li><a href="http://www.apache.org/security/" class="external-link" rel="nofollow">Security</a></li>
+    </ul>
+
+    <h3><a name="Navigation-Upcoming"></a>Upcoming</h3>
+
+</div>
+
+<!-- navigation -->
+          
+        </div><!-- leftColumn -->
+      <div id="rightColumn">
+
+
+
+    <div class="nav">
+        <div class="nav_prev">
+        
+            <a href="../ch7-handler/ch7-handler.html">Chapter 7 - Handler</a>
+		
+        </div>
+        <div class="nav_up">
+        
+            <a href="../user-guide-toc.html">User Guide</a>
+		
+        </div>
+        <div class="nav_next">
+        
+            <a href="../ch9-connector/ch9-connector.html">Chapter 9 - Connector</a>
+		
+        </div>
+        <div class="clearfix"></div>
+    </div>
+
+
+<h1 id="chapter-8-acceptor">Chapter 8 - Acceptor</h1>
+<p>In order to build a server, you need to select an implementation of the <em>IoAcceptor</em> interface.</p>
+<h2 id="ioacceptor">IoAcceptor</h2>
+<p>Basically, this interface is named because of the <em>accept()</em> method, responsible for the creation of new connection between a client and the server. The server accepts incoming connection request.</p>
+<p>At some point, we could have named this interface 'Server'.</p>
+<p>As we may deal with more than one kind of transport (TCP/UDP/...), we have more than one implementation for this interface. It would be very unlikely that you need to implement a new one.</p>
+<p>We have many of those implementing classes</p>
+<ul>
+<li><strong>NioSocketAcceptor</strong> : the non-blocking Socket transport <em>IoAcceptor</em></li>
+<li><strong>NioDatagramAcceptor</strong> : the non-blocking UDP transport <em>IoAcceptor</em></li>
+<li><strong>AprSocketAcceptor</strong> : the blocking Socket transport <em>IoAcceptor</em>, based on APR</li>
+<li><strong>VmPipeSocketAcceptor</strong> : the in-VM <em>IoAcceptor</em></li>
+</ul>
+<p>Just pick the one that fit your need.</p>
+<p>Here is the class diagram for the <em>IoAcceptor</em> interfaces and classes :</p>
+<p><img alt="" src="../../../staticresources/images/mina/IoServiceAcceptor.png" /></p>
+<h2 id="creation">Creation</h2>
+<p>You first have to select the type of <em>IoAcceptor</em> you want to instanciate. This is a choice you will made early in the process, as it all boils down to which network protocol you will use. Let's see with an example how it works :</p>
+<div class="codehilite"><pre><span class="kd">public</span> <span class="nf">TcpServer</span><span class="o">()</span> <span class="kd">throws</span> <span class="n">IOException</span> <span class="o">{</span>
+    <span class="c1">// Create a TCP acceptor</span>
+    <span class="n">IoAcceptor</span> <span class="n">acceptor</span> <span class="o">=</span> <span class="k">new</span> <span class="n">NioSocketAcceptor</span><span class="o">();</span>
+
+    <span class="c1">// Associate the acceptor to an IoHandler instance (your application)</span>
+    <span class="n">acceptor</span><span class="o">.</span><span class="na">setHandler</span><span class="o">(</span><span class="k">this</span><span class="o">);</span>
+
+    <span class="c1">// Bind : this will start the server...</span>
+    <span class="n">acceptor</span><span class="o">.</span><span class="na">bind</span><span class="o">(</span><span class="k">new</span> <span class="n">InetSocketAddress</span><span class="o">(</span><span class="n">PORT</span><span class="o">));</span>
+
+    <span class="n">System</span><span class="o">.</span><span class="na">out</span><span class="o">.</span><span class="na">println</span><span class="o">(</span><span class="s">&quot;Server started...&quot;</span><span class="o">);</span>
+<span class="o">}</span>
+</pre></div>
+
+
+<p>That's it ! You have created a TCP server. If you want to start an UDP server, simply replace the first line of code :</p>
+<div class="codehilite"><pre><span class="o">...</span>
+<span class="c1">// Create an UDP acceptor</span>
+<span class="n">IoAcceptor</span> <span class="n">acceptor</span> <span class="o">=</span> <span class="k">new</span> <span class="n">NioDatagramAcceptor</span><span class="o">();</span>
+<span class="o">...</span>
+</pre></div>
+
+
+<h2 id="disposal">Disposal</h2>
+<p>The service can be stopped by calling the <em>dispose()</em> method. The service will be stopped only when all the pending sessions have been processed :</p>
+<div class="codehilite"><pre><span class="c1">// Stop the service, waiting for the pending sessions to be inactive</span>
+<span class="n">acceptor</span><span class="o">.</span><span class="na">dispose</span><span class="o">();</span>
+</pre></div>
+
+
+<p>You can also wait for every thread being executed to be properly completed by passing a boolean parameter to this method :</p>
+<div class="codehilite"><pre><span class="c1">// Stop the service, waiting for the processing session to be properly completed</span>
+<span class="n">acceptor</span><span class="o">.</span><span class="na">dispose</span><span class="o">(</span> <span class="kc">true</span> <span class="o">);</span>
+</pre></div>
+
+
+<h2 id="status">Status</h2>
+<p>You can get the <em>IoService</em> status by calling one of the following methods :</p>
+<ul>
+<li><em>isActive()</em> : true if the service can accept incoming requests</li>
+<li><em>isDisposing()</em> : true if the <em>dispose()</em> method has been called. It does not tell if the service is actually stopped (some sessions might be processed)</li>
+<li><em>isDisposed()</em> : true if the <em>dispose(boolean)</em> method has been called, and the executing threads have been completed.</li>
+</ul>
+<h2 id="managing-the-iohandler">Managing the IoHandler</h2>
+<p>You can add or get the associated <em>IoHandler</em> when the service has been instanciated. Youjust have to call the <em>setHandler(IoHandler)</em> or <em>getHandler()</em> methods.</p>
+<h2 id="managing-the-filters-chain">Managing the Filters chain</h2>
+<p>if you want to manage the filters chain, you will have to call the <em>getFilterChain()</em> method. Here is an example :</p>
+<div class="codehilite"><pre><span class="c1">// Add a logger filter</span>
+<span class="n">DefaultIoFilterChainBuilder</span> <span class="n">chain</span> <span class="o">=</span> <span class="n">acceptor</span><span class="o">.</span><span class="na">getFilterChain</span><span class="o">();</span>
+<span class="n">chain</span><span class="o">.</span><span class="na">addLast</span><span class="o">(</span><span class="s">&quot;logger&quot;</span><span class="o">,</span> <span class="k">new</span> <span class="n">LoggingFilter</span><span class="o">());</span>
+</pre></div>
+
+
+<p>You can also create the chain before and set it into the service :</p>
+<div class="codehilite"><pre><span class="c1">// Add a logger filter</span>
+<span class="n">DefaultIoFilterChainBuilder</span> <span class="n">chain</span> <span class="o">=</span> <span class="k">new</span> <span class="n">DefaultIoFilterChainBuilder</span><span class="o">();</span>
+<span class="n">chain</span><span class="o">.</span><span class="na">addLast</span><span class="o">(</span><span class="s">&quot;logger&quot;</span><span class="o">,</span> <span class="k">new</span> <span class="n">LoggingFilter</span><span class="o">());</span>
+
+<span class="c1">// And inject the created chain builder in the service</span>
+<span class="n">acceptor</span><span class="o">.</span><span class="na">setFilterChainBuilder</span><span class="o">(</span><span class="n">chain</span><span class="o">);</span>
+</pre></div>
+
+
+<h2></h2>
+
+
+    <div class="nav">
+        <div class="nav_prev">
+        
+            <a href="../ch7-handler/ch7-handler.html">Chapter 7 - Handler</a>
+		
+        </div>
+        <div class="nav_up">
+        
+            <a href="../user-guide-toc.html">User Guide</a>
+		
+        </div>
+        <div class="nav_next">
+        
+            <a href="../ch9-connector/ch9-connector.html">Chapter 9 - Connector</a>
+		
+        </div>
+        <div class="clearfix"></div>
+    </div>
+
+
+                </div><!-- rightColumn -->
+                <div id="endContent"></div>
+            </div><!-- content -->
+            <div id="footer">&copy; 2003-2012, <a href="http://www.apache.org">The Apache Software Foundation</a> - <a href="./../../../privacy-policy.html">Privacy Policy</a><br />
+                Apache MINA, MINA, Apache Vysper, Vysper, Apache SSHd, SSHd, Apache FtpServer, FtpServer, Apache AsyncWeb, AsyncWeb,
+                Apache, the Apache feather logo, and the Apache Mina project logos are trademarks of The Apache Software Foundation.
+            </div>
+        </div><!-- container -->
+    </body>
+</html>
+