directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Apache Wiki <wikidi...@apache.org>
Subject [Directory Wiki] Update of "MinaTutorial" by sishen
Date Tue, 31 Oct 2006 09:27:42 GMT
Dear Wiki user,

You have subscribed to a wiki page or wiki category on "Directory Wiki" for change notification.

The following page has been changed by sishen:
http://wiki.apache.org/directory/MinaTutorial

------------------------------------------------------------------------------
  {{{
  package org.apache.mina.examples.echoserver;
  
+ import org.apache.mina.common.ByteBuffer;
+ import org.apache.mina.common.IoHandlerAdapter;
- import org.apache.mina.common.*;
+ import org.apache.mina.common.IoSession;
- import org.apache.mina.io.*;
- import org.apache.mina.io.socket.*;
+ import org.apache.mina.common.TransportType;
+ import org.apache.mina.transport.socket.nio.SocketSessionConfig;
  
  public class EchoProtocolHandler extends IoHandlerAdapter
  {
      public void sessionCreated( IoSession session )
      {
+         if (session.getTransportType() == TransportType.SOCKET) {
+             ((SocketSessionConfig)session.getConfig()).setReceiveBufferSize(2048);
-         SessionConfig cfg = session.getConfig();
-         if( cfg instanceof SocketSessionConfig )
-         {
-             SocketSessionConfig scfg = ( SocketSessionConfig ) cfg ) ;
- scfg.setSessionReceiveBufferSize( 2048 );
          }
      }
  
@@ -83, +82 @@

          session.close();
      }
  
-     public void dataRead( IoSession session, ByteBuffer rb )
+     public void dataRead( IoSession session, Object message )
+     {
+         if (!(message instanceof ByteBuffer))
+             return;
-     {
+     	
+         ByteBuffer rb = (ByteBuffer)message;
          // Write the received data back to remote peer
          ByteBuffer wb = ByteBuffer.allocate( rb.remaining() );
          wb.put( rb );
          wb.flip();
-         session.write( wb, null );
+         session.write( wb );
      }
  }
  }}}

Mime
View raw message