mina client sample

package com;

import java.net.InetSocketAddress;

import org.apache.mina.core.future.ConnectFuture;
import org.apache.mina.filter.codec.ProtocolCodecFilter;
import org.apache.mina.filter.codec.textline.TextLineCodecFactory;
import org.apache.mina.transport.socket.nio.NioSocketConnector;

import com.ClientHandler;

public class Test {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String host = "www.sina.com.cn";
int port = 80;

NioSocketConnector connector = new NioSocketConnector();
connector.setConnectTimeoutMillis(30 * 1000L);
connector.getFilterChain().addLast("codec", new ProtocolCodecFilter(new TextLineCodecFactory()));
ClientHandler handler = null;
handler = new ClientHandler();
connector.setHandler(handler);
ConnectFuture future = null;
future = connector.connect(new InetSocketAddress(host, port));
System.out.println("connecting ... ");
//future.join();
//future.getSession().getCloseFuture().join();
future.awaitUninterruptibly(30000);
future.getSession().getCloseFuture().awaitUninterruptibly(30000);
connector.dispose();
}

}

你可能感兴趣的:(apache,.net,socket,Mina)