Search in sources :

Example 6 with WebSocketCodec

use of com.firenio.codec.http11.WebSocketCodec in project baseio by generallycloud.

the class TestHttpLoadServer method main.

public static void main(String[] args) throws Exception {
    IoEventHandle eventHandle = new IoEventHandle() {

        @Override
        public void accept(Channel ch, Frame frame) throws Exception {
            HttpFrame f = (HttpFrame) frame;
            f.setConnection(HttpConnection.KEEP_ALIVE);
            f.setContentType(HttpContentType.text_plain);
            f.setString("Hello World", ch);
            ch.writeAndFlush(f);
            ch.release(f);
        }
    };
    NioEventLoopGroup group = new NioEventLoopGroup();
    group.setMemoryCapacity(1024 * 1024 * 64);
    group.setMemoryUnit(512);
    group.setEventLoopSize(2);
    ChannelAcceptor context = new ChannelAcceptor(group, 8080);
    context.addProtocolCodec(new HttpCodec(8));
    context.addProtocolCodec(new WebSocketCodec());
    context.setIoEventHandle(eventHandle);
    context.addChannelEventListener(new LoggerChannelOpenListener());
    context.bind();
}
Also used : IoEventHandle(com.firenio.component.IoEventHandle) Frame(com.firenio.component.Frame) HttpFrame(com.firenio.codec.http11.HttpFrame) HttpCodec(com.firenio.codec.http11.HttpCodec) Channel(com.firenio.component.Channel) ChannelAcceptor(com.firenio.component.ChannelAcceptor) HttpFrame(com.firenio.codec.http11.HttpFrame) NioEventLoopGroup(com.firenio.component.NioEventLoopGroup) WebSocketCodec(com.firenio.codec.http11.WebSocketCodec) LoggerChannelOpenListener(com.firenio.component.LoggerChannelOpenListener)

Aggregations

WebSocketCodec (com.firenio.codec.http11.WebSocketCodec)6 LoggerChannelOpenListener (com.firenio.component.LoggerChannelOpenListener)5 Channel (com.firenio.component.Channel)4 Frame (com.firenio.component.Frame)4 IoEventHandle (com.firenio.component.IoEventHandle)4 ClientHttpCodec (com.firenio.codec.http11.ClientHttpCodec)3 ClientHttpFrame (com.firenio.codec.http11.ClientHttpFrame)3 ChannelConnector (com.firenio.component.ChannelConnector)3 NioEventLoopGroup (com.firenio.component.NioEventLoopGroup)3 HttpCodec (com.firenio.codec.http11.HttpCodec)2 HttpFrame (com.firenio.codec.http11.HttpFrame)2 WebSocketFrame (com.firenio.codec.http11.WebSocketFrame)2 ChannelAcceptor (com.firenio.component.ChannelAcceptor)2 SslContext (com.firenio.component.SslContext)2 IOException (java.io.IOException)2 LifeCycle (com.firenio.LifeCycle)1 LifeCycleListener (com.firenio.LifeCycleListener)1 WebSocketChannelListener (com.firenio.codec.http11.WebSocketChannelListener)1 WsUpgradeRequestFrame (com.firenio.codec.http11.WsUpgradeRequestFrame)1 Http2Codec (com.firenio.codec.http2.Http2Codec)1