mina client sample
2013年06月11日
⁄ 综合
⁄ 共 1272字 ⁄ 字号
小 中 大
- public class Client
- {
- private static final String HOSTNAME = "localhost";
- private static final int PORT = 20000;
-
-
-
- public static void main( String[] args ) throws Throwable
- {
- SocketConnector connector = new SocketConnector();
-
- SocketConnectorConfig cfg = new SocketConnectorConfig();
- cfg.getFilterChain().addLast(
- "codec",
- new ProtocolCodecFilter( new ObjectSerializationCodecFactory() ) );
-
- cfg.getFilterChain().addLast( "logger", new LoggingFilter() );
-
- IoSession session;
- try {
- ConnectFuture future = connector.connect(new InetSocketAddress(
- HOSTNAME, PORT), new ClientSessionHandler("Hi hi :("), cfg);
-
- future.join();
- session = future.getSession();
- } catch (RuntimeIOException e) {
- System.err.println("Failed to connect.");
- e.printStackTrace();
- }
-
-
- session.getCloseFuture().join();
- System.out.println(session,"### all done! !");
- }