现在的位置: 首页 > 综合 > 正文

mina client sample

2013年06月11日 ⁄ 综合 ⁄ 共 1272字 ⁄ 字号 评论关闭
  1. public class Client   
  2. {   
  3.     private static final String HOSTNAME = "localhost";   
  4.     private static final int PORT = 20000;   
  5.   
  6.   
  7.       
  8.     public static void main( String[] args ) throws Throwable   
  9.     {   
  10.         SocketConnector connector = new SocketConnector();          
  11.         // Configure the service.   
  12.         SocketConnectorConfig cfg = new SocketConnectorConfig();   
  13.                  cfg.getFilterChain().addLast(   
  14.                     "codec",   
  15.                     new ProtocolCodecFilter( new ObjectSerializationCodecFactory() ) );   
  16.   
  17.         cfg.getFilterChain().addLast( "logger"new LoggingFilter() );   
  18.           
  19.         IoSession session;   
  20.                     try {   
  21.                 ConnectFuture future = connector.connect(new InetSocketAddress(   
  22.                         HOSTNAME, PORT), new ClientSessionHandler("Hi hi :("), cfg);   
  23.   
  24.                 future.join();   
  25.                 session = future.getSession();   
  26.                         } catch (RuntimeIOException e) {   
  27.                 System.err.println("Failed to connect.");   
  28.                 e.printStackTrace();   
  29.                            }   
  30.            
  31.         // wait until the summation is done   
  32.         session.getCloseFuture().join();   
  33.         System.out.println(session,"### all done!  !");   
  34.     }  

抱歉!评论已关闭.