Package org.apache.mina.filter.codec

Examples of org.apache.mina.filter.codec.ProtocolCodecFilter


        }

        if ( session.getTransportMetadata().isConnectionless() )
        {
            session.getFilterChain().addFirst( "codec",
                new ProtocolCodecFilter( DnsProtocolUdpCodecFactory.getInstance() ) );
        }
        else
        {
            session.getFilterChain().addFirst( "codec",
                new ProtocolCodecFilter( DnsProtocolTcpCodecFactory.getInstance() ) );
        }
    }
View Full Code Here


            // Create a service configuration
            SocketAcceptorConfig cfg = new SocketAcceptorConfig();
            cfg.setReuseAddress( true );
            cfg.getFilterChain().addLast(
                    "protocolFilter",
                    new ProtocolCodecFilter( new HttpServerProtocolCodecFactory() ) );
            cfg.getFilterChain().addLast( "logger", new LoggingFilter() );

            acceptor.bind( new InetSocketAddress( port ), new ServerHandler(), cfg );

            System.out.println( "Server now listening on port " + port );
View Full Code Here

        SocketAcceptorConfig cfg = new SocketAcceptorConfig();
        cfg.setReuseAddress( true );
        cfg.getFilterChain().addLast( "logger", new LoggingFilter() );
        cfg.getFilterChain().addLast(
                "codec",
                new ProtocolCodecFilter(
                        new TextLineCodecFactory( Charset.forName( "UTF-8" ) ) ) );

        // Bind
        acceptor.bind(
                new InetSocketAddress( PORT ),
View Full Code Here

        cfg.setReuseAddress( true );
        if( USE_CUSTOM_CODEC )
        {
            cfg.getFilterChain().addLast(
                    "codec",
                    new ProtocolCodecFilter( new SumUpProtocolCodecFactory( true ) ) );
        }
        else
        {
            cfg.getFilterChain().addLast(
                    "codec",
                    new ProtocolCodecFilter( new ObjectSerializationCodecFactory() ) );
        }
        cfg.getFilterChain().addLast( "logger", new LoggingFilter() );

        acceptor.bind(
                new InetSocketAddress( SERVER_PORT ),
View Full Code Here

        cfg.setConnectTimeout( CONNECT_TIMEOUT );
        if( USE_CUSTOM_CODEC )
        {
            cfg.getFilterChain().addLast(
                    "codec",
                    new ProtocolCodecFilter( new SumUpProtocolCodecFactory( false ) ) );
        }
        else
        {
            cfg.getFilterChain().addLast(
                    "codec",
                    new ProtocolCodecFilter( new ObjectSerializationCodecFactory() ) );
        }
        cfg.getFilterChain().addLast( "logger", new LoggingFilter() );
       
        IoSession session;
        for( ;; )
View Full Code Here

*/
public class ChatServer {
  public static void main(String [] args) {
    NioSocketAcceptor m_tcpAcceptor = new NioSocketAcceptor();
    m_tcpAcceptor.getFilterChain().addLast("codec",
        new ProtocolCodecFilter(new TextLineCodecFactory(
        Charset.forName("US-ASCII"))));
    m_tcpAcceptor.setHandler(new ChatProtocolHandler());
    try {
      m_tcpAcceptor.bind(new InetSocketAddress(7001));
      System.out.println("INFO: Chat server started.");
View Full Code Here

    /*
     * Connect via TCP to game server
     */
    NioSocketConnector connector = new NioSocketConnector();
    connector.getFilterChain().addLast("codec",
        new ProtocolCodecFilter(
            new TextLineCodecFactory(Charset.forName("US-ASCII"))));
    connector.setHandler(new TcpProtocolHandler(this));
    ConnectFuture cf = connector.connect(new InetSocketAddress(HOST, 7002));
    cf.addListener(new IoFutureListener() {
      public void operationComplete(IoFuture s) {
        try {
          if(s.getSession() != null && s.getSession().isConnected()) {
            m_packetGen.setTcpSession(s.getSession());
          } else {
            messageDialog("Connection timed out.\n"
                + "The server may be offline.\n"
                + "Contact an administrator for assistance.", getDisplay());
            HOST = "";
            m_packetGen = null;
          }
        }catch(RuntimeIoException e){
          messageDialog("Connection timed out.\n"
              + "The server may be offline.\n"
              + "Contact an administrator for assistance.", getDisplay());
          HOST = "";
          m_packetGen = null;
        }catch (Exception e) {
          e.printStackTrace();
          messageDialog("Connection timed out.\n"
              + "The server may be offline.\n"
              + "Contact an administrator for assistance.", getDisplay());
          HOST = "";
          m_packetGen = null;
        }
      }
    });
    /*
     * Connect via UDP to game server
     */
    NioDatagramConnector udp = new NioDatagramConnector();
    udp.getFilterChain().addLast("codec",
        new ProtocolCodecFilter(
            new TextLineCodecFactory(Charset.forName("US-ASCII"))));
    udp.setHandler(new UdpProtocolHandler(this));
    cf = udp.connect(new InetSocketAddress(HOST, 7005));
    cf.addListener(new IoFutureListener() {
      public void operationComplete(IoFuture s) {
        try {
          if(s.getSession().isConnected()) {
            m_packetGen.setUdpSession(s.getSession());
          } else {
            messageDialog("Connection timed out.\n"
                + "The server may be offline.\n"
                + "Contact an administrator for assistance.", getDisplay());
            HOST = "";
            m_packetGen = null;
          }
        }catch(RuntimeIoException e){
          messageDialog("Connection timed out.\n"
              + "The server may be offline.\n"
              + "Contact an administrator for assistance.", getDisplay());
          HOST = "";
          m_packetGen = null;
        } catch (Exception e) {
          e.printStackTrace();
          messageDialog("Connection timed out.\n"
              + "The server may be offline.\n"
              + "Contact an administrator for assistance.", getDisplay());
          HOST = "";
          m_packetGen = null;
        }
      }
    });
    /*
     * Connect via TCP to chat server
     */
    NioSocketConnector chat = new NioSocketConnector();
    chat.getFilterChain().addLast("codec",
        new ProtocolCodecFilter(
            new TextLineCodecFactory(Charset.forName("US-ASCII"))));
    chat.setHandler(new ChatProtocolHandler());
    ConnectFuture cf2 = connector.connect(new InetSocketAddress(CHATHOST, 7001));
    cf2.addListener(new IoFutureListener() {
      public void operationComplete(IoFuture s) {
View Full Code Here

       
    /*
     * Bind the TCP port
     */
    m_tcpAcceptor = new NioSocketAcceptor();
    m_tcpAcceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new PokenetCodecFactory()));
    m_tcpAcceptor.setHandler(m_tcpProtocolHandler);
    try {
      m_tcpAcceptor.bind(new InetSocketAddress(7002));
      System.out.println("INFO: TCP acceptor started.");
    } catch (Exception e) {
      e.printStackTrace();
      return;
    }
    /*
     * Bind the UDP port
     */
    m_udpAcceptor = new NioDatagramAcceptor();
    m_udpAcceptor.setHandler(m_udpProtocolHandler);
    DefaultIoFilterChainBuilder chain = m_udpAcceptor.getFilterChain();

    chain.addLast("codec", new ProtocolCodecFilter(new PokenetCodecFactory()));
    DatagramSessionConfig dcfg = m_udpAcceptor.getSessionConfig();
    dcfg.setReuseAddress(true);
    try {
      m_udpAcceptor.bind(new InetSocketAddress(7005));
      System.out.println("INFO: UDP acceptor started.");
View Full Code Here

           
            //connector.setHandler( arg0 );
           
            connector.getFilterChain().addLast(
                                               "codec",
                                               new ProtocolCodecFilter(
                                                       new ObjectSerializationCodecFactory()));

            ConnectFuture future1 = connector.connect( address );
            future1.join();
            if (!future1.isConnected()) {
View Full Code Here

        acceptor = new NioSocketAcceptor();

        acceptor.getFilterChain().addLast( "logger",
                                           new LoggingFilter() );
        acceptor.getFilterChain().addLast( "codec",
                                           new ProtocolCodecFilter( new ObjectSerializationCodecFactory() ) );

        acceptor.setHandler( handler );
        acceptor.getSessionConfig().setReadBufferSize( 2048 );
        acceptor.getSessionConfig().setIdleTime( IdleStatus.BOTH_IDLE, 10 );
        acceptor.bind( new InetSocketAddress( "127.0.0.1", port ) );
View Full Code Here

TOP

Related Classes of org.apache.mina.filter.codec.ProtocolCodecFilter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.