Last active
August 29, 2015 14:01
-
-
Save yongboy/54f41e871abea0c6d4ee to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import io.mqtt.handler.HttpRequestHandler; | |
import io.mqtt.handler.MqttMessageHandler; | |
import io.mqtt.handler.coder.MqttMessageWebSocketFrameDecoder; | |
import io.mqtt.handler.coder.MqttMessageWebSocketFrameEncoder; | |
import io.mqtt.handler.http.HttpJsonpTransport; | |
import io.netty.channel.ChannelInitializer; | |
import io.netty.channel.socket.SocketChannel; | |
import io.netty.handler.codec.http.HttpObjectAggregator; | |
import io.netty.handler.codec.http.HttpServerCodec; | |
import io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler; | |
public class WebsocketChannelInitializer extends ChannelInitializer<SocketChannel> { | |
private final static String websocketUri = "/websocket"; | |
private HttpRequestHandler httpRequestHandler = new HttpRequestHandler( | |
websocketUri); | |
static { | |
HttpJsonpTransport httpJsonpTransport = new HttpJsonpTransport(); | |
HttpRequestHandler.registerTransport(httpJsonpTransport); | |
} | |
@Override | |
public void initChannel(final SocketChannel ch) throws Exception { | |
ch.pipeline().addLast( | |
new HttpServerCodec(), | |
new MqttMessageWebSocketFrameEncoder(), | |
new HttpObjectAggregator(65536), | |
httpRequestHandler, | |
new WebSocketServerProtocolHandler(websocketUri), | |
new MqttMessageWebSocketFrameDecoder(), | |
new MqttMessageHandler()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment