Package org.apache.mina.filter.codec.textline

Examples of org.apache.mina.filter.codec.textline.TextLineCodecFactory


     * 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) {
        try {
View Full Code Here


        connector.setProxyIoSession(proxyIoSession);

        LineDelimiter delim = new LineDelimiter("\r\n");
        targetConnector.getFilterChain().addLast(
                "codec",
                new ProtocolCodecFilter(new TextLineCodecFactory(Charset
                        .forName("UTF-8"), delim, delim)));

        connector.setHandler(new TelnetSessionHandler());

        IoSession session;
View Full Code Here

            sslFilter = new SslFilter(BogusSslContextFactory.getInstance(true));
            acceptor.getFilterChain().addLast("sslFilter", sslFilter);
        }
        acceptor.getFilterChain().addLast(
                "codec",
                new ProtocolCodecFilter(new TextLineCodecFactory(Charset
                        .forName("UTF-8"))));

        EchoHandler handler = new EchoHandler();
        acceptor.setHandler(handler);
        acceptor.bind(new InetSocketAddress(0));
View Full Code Here

                    .getInstance(true));
            acceptor.getFilterChain().addLast("sslFilter", sslFilter);
        }
        acceptor.getFilterChain().addLast(
                "codec",
                new ProtocolCodecFilter(new TextLineCodecFactory(Charset
                        .forName("UTF-8"))));

        EchoHandler handler = new EchoHandler();
        acceptor.bind(socketAddress, handler);
        System.out.println("MINA server started.");
View Full Code Here

        // Prepare the configuration
        SocketAcceptorConfig cfg = new SocketAcceptorConfig();
        cfg.setReuseAddress(true);
        Charset charset = Charset.forName("UTF-8");
        cfg.getFilterChain().addLast("codec", new ProtocolCodecFilter(new TextLineCodecFactory(charset)));

        // Bind
        acceptor.bind(new InetSocketAddress(port), new ReverseProtocolHandler(), cfg);
    }
View Full Code Here

            sslFilter = new SslFilter(BogusSslContextFactory.getInstance(true));
            acceptor.getFilterChain().addLast("sslFilter", sslFilter);
        }
        acceptor.getFilterChain().addLast(
                "codec",
                new ProtocolCodecFilter(new TextLineCodecFactory(Charset
                        .forName("UTF-8"))));

        EchoHandler handler = new EchoHandler();
        acceptor.setHandler(handler);
        acceptor.bind(new InetSocketAddress(0));
View Full Code Here

        if (codecFactory == null) {
            boolean textline = ObjectConverter.toBool(parameters.get("textline"));
            if (textline) {
                Charset encoding = getEncodingParameter(type, parameters);
                codecFactory = new TextLineCodecFactory(encoding);
                if (LOG.isDebugEnabled()) {
                    LOG.debug(type + ": Using TextLineCodecFactory: " + codecFactory + " using encoding: "
                              + encoding);
                }
            } else {
View Full Code Here

        // Prepare the configuration
        SocketAcceptorConfig cfg = new SocketAcceptorConfig();
        cfg.setReuseAddress(true);
        Charset charset = Charset.forName("UTF-8");
        cfg.getFilterChain().addLast("codec", new ProtocolCodecFilter(new TextLineCodecFactory(charset)));

        // Bind
        acceptor.bind(new InetSocketAddress(port), new ReverseProtocolHandler(), cfg);

        // System.out.println("Listening on port " + port);
View Full Code Here

                    .getInstance(true));
            acceptor.getFilterChain().addLast("sslFilter", sslFilter);
        }
        acceptor.getFilterChain().addLast(
                "codec",
                new ProtocolCodecFilter(new TextLineCodecFactory(Charset
                        .forName("UTF-8"))));

        EchoHandler handler = new EchoHandler();
        acceptor.bind(socketAddress, handler);
        System.out.println("MINA server started.");
View Full Code Here

            sslFilter = new SslFilter(BogusSslContextFactory.getInstance(true));
            acceptor.getFilterChain().addLast("sslFilter", sslFilter);
        }
        acceptor.getFilterChain().addLast(
                "codec",
                new ProtocolCodecFilter(new TextLineCodecFactory(Charset
                        .forName("UTF-8"))));

        EchoHandler handler = new EchoHandler();
        acceptor.setHandler(handler);
        acceptor.bind(new InetSocketAddress(0));
View Full Code Here

TOP

Related Classes of org.apache.mina.filter.codec.textline.TextLineCodecFactory

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.