org.apache.mina.filter.codec.serialization.ObjectSerializationCodecFactory Java Examples

The following examples show how to use org.apache.mina.filter.codec.serialization.ObjectSerializationCodecFactory. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MinaClient.java    From java-study with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
public static void main(String[] args) {
   	   // 设置链接超时时间
       connector.setConnectTimeout(30000);
       // 添加过滤器  可序列话的对象 
       connector.getFilterChain().addLast(
               "codec",
               new ProtocolCodecFilter(new ObjectSerializationCodecFactory()));
       // 添加业务逻辑处理器类
       connector.setHandler(new MinaClientHandler());
       ConnectFuture future = connector.connect(new InetSocketAddress(
               HOST, PORT));// 创建连接
       future.awaitUninterruptibly();// 等待连接创建完成
       session = future.getSession();// 获得session
       
   	bindstart();
   	pushstart();
   }
 
Example #2
Source File: HelloTcpClient.java    From mina-examples with MIT License 6 votes vote down vote up
public static void main(String[] args) {
	NioSocketConnector connector = new NioSocketConnector(); //TCP Connector
	connector.getFilterChain().addLast("logging", new LoggingFilter());
	connector.getFilterChain().addLast("codec",new ProtocolCodecFilter(new ObjectSerializationCodecFactory()));
    connector.getFilterChain().addLast("mdc", new MdcInjectionFilter());
	connector.setHandler(new HelloClientHandler());
    IoSession session;

    for (;;) {
        try {
            ConnectFuture future = connector.connect(new InetSocketAddress(HOSTNAME, PORT));
            future.awaitUninterruptibly();
            session = future.getSession();
            break;
        } catch (RuntimeIoException e) {
            System.err.println("Failed to connect.");
            e.printStackTrace();
        }
    }
    session.getCloseFuture().awaitUninterruptibly();
    connector.dispose();
}
 
Example #3
Source File: ClientTestServer.java    From java-study with Apache License 2.0 5 votes vote down vote up
public IoConnector creatClient(){  
    IoConnector connector=new NioSocketConnector();   
    connector.setConnectTimeoutMillis(30000);   
    connector.getFilterChain().addLast("codec",   
    new ProtocolCodecFilter(new ObjectSerializationCodecFactory()));  
    connector.setHandler(new MinaClientHandler());  
    return connector;  
}
 
Example #4
Source File: MinaClient.java    From MtgDesktopCompanion with GNU General Public License v3.0 5 votes vote down vote up
public MinaClient(String server, int port) {

		p = new Player();
		connector = new NioSocketConnector();
		connector.getFilterChain().addLast("codec", new ProtocolCodecFilter(new ObjectSerializationCodecFactory()));
		connector.setHandler(adapter);

		ConnectFuture connFuture = connector.connect(new InetSocketAddress(server, port));
		connFuture.awaitUninterruptibly();
		session = connFuture.getSession();
	}
 
Example #5
Source File: MTGGameRoomServer.java    From MtgDesktopCompanion with GNU General Public License v3.0 5 votes vote down vote up
public MTGGameRoomServer() throws IOException {

		super();
		acceptor = new NioSocketAcceptor();
		acceptor.setHandler(adapter);
		acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new ObjectSerializationCodecFactory()));
		acceptor.getSessionConfig().setReadBufferSize(getInt("BUFFER-SIZE"));
		acceptor.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE,getInt("IDLE-TIME"));
	}
 
Example #6
Source File: HelloUdpServer.java    From mina-examples with MIT License 5 votes vote down vote up
public static void main(String[] args) throws Exception {
	NioDatagramAcceptor acceptor = new NioDatagramAcceptor();//UDP Acceptor
	acceptor.getFilterChain().addLast("logging", new LoggingFilter());
	acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new ObjectSerializationCodecFactory()));
	acceptor.getFilterChain().addLast("mdc", new MdcInjectionFilter());
	acceptor.setHandler(new HelloServerHandler());
	acceptor.getSessionConfig().setReadBufferSize(2048);
	acceptor.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE, 10);
	DatagramSessionConfig dcfg = acceptor.getSessionConfig();
	dcfg.setReuseAddress(true);
	acceptor.bind(new InetSocketAddress(PORT));
}
 
Example #7
Source File: HelloTcpServer.java    From mina-examples with MIT License 5 votes vote down vote up
public static void main(String[] args) throws Exception {
	IoAcceptor acceptor = new NioSocketAcceptor(); //TCP Acceptor
	acceptor.getFilterChain().addLast("logging", new LoggingFilter());
	acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new ObjectSerializationCodecFactory()));
	acceptor.getFilterChain().addLast("mdc", new MdcInjectionFilter());
	acceptor.setHandler(new HelloServerHandler());
	acceptor.getSessionConfig().setReadBufferSize(2048);
	acceptor.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE, 10);
	acceptor.bind(new InetSocketAddress(PORT));
}