Open GoogleCodeExporter opened 9 years ago
I've managed to successfully connect through WebSockets to moquette broker.
I've changed NettyAcceptor method:
public void initialize(IMessaging messaging, Properties props) throws
IOException {
m_bossGroup = new NioEventLoopGroup();
m_workerGroup = new NioEventLoopGroup();
final NettyMQTTHandler handler = new NettyMQTTHandler();
handler.setMessaging(messaging);
ServerBootstrap b = new ServerBootstrap();
b.group(m_bossGroup, m_workerGroup)
.channel(NioServerSocketChannel.class)
.childHandler(new ChannelInitializer<SocketChannel>()
{
@Override
public void initChannel(SocketChannel ch) throws Exception
{
boolean handleCloseFrames = false;
ChannelPipeline pipeline = ch.pipeline();
pipeline.addLast("codec-http", new HttpServerCodec());
pipeline.addLast("aggregator", new HttpObjectAggregator(65536));
pipeline.addLast("handler", new WebSocketServerProtocolHandler("/mqtt", "mqttv3.1"));
pipeline.addLast("messageToMessage", new MessageToMessageCodec<WebSocketFrame, AbstractMessage>()
{
@Override
protected void encode(ChannelHandlerContext ctx, AbstractMessage msg, List<Object> out) throws Exception
{
BinaryWebSocketFrame result = new BinaryWebSocketFrame();
MQTTEncoder encoder = new MQTTEncoder();
encoder.encode(ctx, msg, result.content());
}
@Override
protected void decode(ChannelHandlerContext ctx, WebSocketFrame msg, List<Object> out) throws Exception
{
if(msg instanceof BinaryWebSocketFrame)
{
ByteBuf bb = msg.content();
MQTTDecoder mqttDecoder = new MQTTDecoder();
mqttDecoder.decode(ctx, bb, out);
}
}
}) ;
;
//pipeline.addFirst("metrics", new BytesMetricsHandler(m_metricsCollector));
pipeline.addFirst("idleStateHandler", new IdleStateHandler(0, 0, Constants.DEFAULT_CONNECT_TIMEOUT));
pipeline.addAfter("idleStateHandler", "idleEventHandler", new MoquetteIdleTimoutHandler());
//pipeline.addLast("logger", new LoggingHandler("Netty", LogLevel.ERROR));
pipeline.addLast("decoder", new MQTTDecoder());
pipeline.addLast("encoder", new MQTTEncoder());
pipeline.addLast("metrics", new MessageMetricsHandler(m_metricsCollector));
pipeline.addLast("handler", handler);
}
})
.option(ChannelOption.SO_BACKLOG, 128)
.option(ChannelOption.SO_REUSEADDR, true)
.childOption(ChannelOption.SO_KEEPALIVE, true);
try {
// Bind and start to accept incoming connections.
// ChannelFuture f = b.bind(Constants.PORT);
ChannelFuture f = b.bind(props.getProperty("host"), Integer.parseInt("1884"));
f.sync();
} catch (InterruptedException ex) {
LOG.error(null, ex);
}
}
Unfortunately just after connection it is lost:
3503 [pool-1-thread-1] INFO ProtocolProcessor - Connected client ID
<clientId-AVKc68oWHt> with clean session true
3505 [pool-1-thread-1] INFO ProtocolProcessor - Lost connection with client
<clientId-AVKc68oWHt>
Do you have any idea how to make it work?
Original comment by radoslaw...@gmail.com
on 16 Mar 2014 at 4:39
Update:
Modified code:
public void initialize(IMessaging messaging, Properties props) throws IOException {
m_bossGroup = new NioEventLoopGroup();
m_workerGroup = new NioEventLoopGroup();
final NettyMQTTHandler handler = new NettyMQTTHandler();
handler.setMessaging(messaging);
ServerBootstrap b = new ServerBootstrap();
b.group(m_bossGroup, m_workerGroup)
.channel(NioServerSocketChannel.class)
.childHandler(new ChannelInitializer<SocketChannel>()
{
@Override
public void initChannel(SocketChannel ch) throws Exception
{
ChannelPipeline pipeline = ch.pipeline();
pipeline.addLast("codec-http", new HttpServerCodec());
pipeline.addLast("aggregator", new HttpObjectAggregator(65536));
pipeline.addLast("handler", new WebSocketServerProtocolHandler("/mqtt", "mqttv3.1"));
pipeline.addLast("messageToMessage", new MessageToMessageCodec<WebSocketFrame, AbstractMessage>()
{
@Override
protected void encode(ChannelHandlerContext ctx, AbstractMessage msg, List<Object> out) throws Exception
{
BinaryWebSocketFrame result = new BinaryWebSocketFrame();
MQTTEncoder encoder = new MQTTEncoder();
encoder.encode(ctx, msg, result.content());
}
@Override
protected void decode(ChannelHandlerContext ctx, WebSocketFrame msg, List<Object> out) throws Exception
{
if(msg instanceof BinaryWebSocketFrame)
{
ByteBuf bb = msg.content();
MQTTDecoder mqttDecoder = new MQTTDecoder();
mqttDecoder.decode(ctx, bb, out);
}
}
}) ;
;
//pipeline.addFirst("metrics", new BytesMetricsHandler(m_metricsCollector));
pipeline.addFirst("idleStateHandler", new IdleStateHandler(0, 0, Constants.DEFAULT_CONNECT_TIMEOUT));
pipeline.addAfter("idleStateHandler", "idleEventHandler", new MoquetteIdleTimoutHandler());
//pipeline.addLast("logger", new LoggingHandler("Netty", LogLevel.ERROR));
pipeline.addLast("decoder", new MQTTDecoder());
pipeline.addLast("encoder", new MQTTEncoder());
pipeline.addLast("metrics", new MessageMetricsHandler(m_metricsCollector));
pipeline.addLast("mqqtHandler", handler);
}
})
.option(ChannelOption.SO_BACKLOG, 128)
.option(ChannelOption.SO_REUSEADDR, true)
.childOption(ChannelOption.SO_KEEPALIVE, true);
try {
// Bind and start to accept incoming connections.
// ChannelFuture f = b.bind(Constants.PORT);
//ChannelFuture f = b.bind(props.getProperty("host"), Integer.parseInt("1884"));
Channel ch = b.bind(1884).sync().channel();
System.out.println("Web socket server started at port " + 1884 + '.');
System.out.println("Open your browser and navigate to http://localhost:" + 1884 + '/');
ch.closeFuture().sync();
//f.sync();
} catch (InterruptedException ex) {
LOG.error(null, ex);
}
}
Original comment by radoslaw...@gmail.com
on 16 Mar 2014 at 5:00
Hi Radoslav,
thank you very much for your your interest and the feature fix, I'll integrate
into mouette as soon as possible.
Thanks a lot!
Andrea
Original comment by selva.an...@gmail.com
on 16 Mar 2014 at 8:22
Let me know if, and how I can help you with that!
Cheers,
Radek
Original comment by radoslaw...@gmail.com
on 17 Mar 2014 at 4:36
[deleted comment]
Hi Andrea,
I've managed to create working WebSocket transport :-)
I've attached modified NettyAcceptor.
Original comment by radoslaw...@gmail.com
on 18 Mar 2014 at 5:12
Attachments:
Hi Radek!
Great job, I'll integrate your changes once I start the next development cycle.
Thanks!
Andrea
Original comment by selva.an...@gmail.com
on 18 Mar 2014 at 8:12
Super cool! nice work Radek!
Original comment by andypiperuk
on 20 Mar 2014 at 2:58
Integrated into moquette 0.6-SNAPSHOT
Added websocket_port = 8080 in moquette.conf
Added trivial websocket test based on Jetty WebSocket client.
Radek, if you want, please check the snapshot against your use case, to have
ack that it works.
Andrea
Original comment by selva.an...@gmail.com
on 18 May 2014 at 10:04
Hi,
I'm having trouble to connect to Moquette 0.6 over WS using Paho 1.0 JS client.
Could you please confirm that the WS is exposed at ws://localhost:8080/ ?
Here's the DEBUG log when I try to connect:
3259 [nioEventLoopGroup-3-1] DEBUG ResourceLeakDetector -
-Dio.netty.noResourceLeakDetection: false
3286 [nioEventLoopGroup-3-1] DEBUG WebSocketServerHandshaker - [id:
0x8e33cd60, /0:0:0:0:0:0:0:1:63214 => /0:0:0:0:0:0:0:1:8088] WS Version V13
server handshake
3290 [nioEventLoopGroup-3-1] DEBUG WebSocketServerHandshaker - WS Version 13
Server Handshake key: M23GhckUGtWcUcMTjF47QA==. Response:
i1C3pyZzBz44rbZOlJyEfza7C6Q=.
3296 [nioEventLoopGroup-3-1] DEBUG WebSocket08FrameDecoder - Decoding
WebSocket Frame opCode=2
3296 [nioEventLoopGroup-3-1] DEBUG WebSocket08FrameDecoder - Decoding
WebSocket Frame length=30
3298 [nioEventLoopGroup-3-1] WARN DefaultChannelPipeline - An
exceptionCaught() event was fired, and it reached at the tail of the pipeline.
It usually means the last handler in the pipeline did not handle the exception.
io.netty.handler.codec.DecoderException:
io.netty.util.IllegalReferenceCountException: refCnt: 0
at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:263)
at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:131)
at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:332)
at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:318)
at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103)
at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:332)
at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:318)
at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103)
at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:332)
at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:318)
at io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler$1.channelRead(WebSocketServerProtocolHandler.java:133)
at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:332)
at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:318)
at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:173)
at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:332)
at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:318)
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:785)
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:100)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:478)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:447)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:341)
at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:101)
at java.lang.Thread.run(Thread.java:744)
Caused by: io.netty.util.IllegalReferenceCountException: refCnt: 0
at io.netty.buffer.AbstractByteBuf.ensureAccessible(AbstractByteBuf.java:1171)
at io.netty.buffer.AbstractByteBuf.checkIndex(AbstractByteBuf.java:1117)
at io.netty.buffer.AbstractByteBuf.getByte(AbstractByteBuf.java:330)
at io.netty.buffer.AbstractByteBuf.readByte(AbstractByteBuf.java:563)
at org.dna.mqtt.moquette.parser.netty.Utils.decodeRemainingLenght(Utils.java:75)
at org.dna.mqtt.moquette.parser.netty.Utils.checkHeaderAvailability(Utils.java:47)
at org.dna.mqtt.moquette.parser.netty.MQTTDecoder.decode(MQTTDecoder.java:55)
at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:232)
... 22 more
Original comment by kart...@gmail.com
on 28 Jul 2014 at 9:16
Yes it' exposed on 8080, on Moquette startup, the shell console is written with
connectors details...I'll investigate the bug.
Thanks for the report
Andrea
Original comment by selva.an...@gmail.com
on 28 Jul 2014 at 9:22
Original comment by selva.an...@gmail.com
on 28 Jul 2014 at 9:27
Hi Karben,
I've tried to replicate the bug with version 0.6, but I wasn't unable.
I attach the js that I used for test, could you check and give feedback if it's
triggers the bug?
Thanks
Original comment by selva.an...@gmail.com
on 4 Aug 2014 at 9:50
Attachments:
We are using .6 and with index.html your provided we are getting when connect
7:59:36,734 DEBUG
io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker:71 - [id:
0x8fa66513, /127.0.0.1:62919 => /127.0.0.1:8080] WS Version V13 server handshake
17:59:36,735 DEBUG
io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker:71 - WS
Version 13 Server Handshake key: 8144k1fvgGGvpPGCRV8ELg==. Response:
tzadcK9GHsxPVjv+qxYEwebYQCA=.
17:59:36,744 DEBUG
io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder:76 - Decoding
WebSocket Frame opCode=1
17:59:36,745 DEBUG
io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder:76 - Decoding
WebSocket Frame length=4
17:59:36,745 WARN io.netty.channel.DefaultChannelPipeline:151 - An
exceptionCaught() event was fired, and it reached at the tail of the pipeline.
It usually means the last handler in the pipeline did not handle the exception.
java.lang.ClassCastException:
io.netty.handler.codec.http.websocketx.TextWebSocketFrame cannot be cast to
org.dna.mqtt.moquette.proto.messages.AbstractMessage
Original comment by bppa...@gmail.com
on 24 Nov 2014 at 11:24
I'm using 0.6 versión with index.html you provided, and using mqttws31.js
downloaded from http://www.eclipse.org/paho/clients/js/, and when trying to hit
connect button, i get next error message on server:
18:35:27,746 DEBUG io.netty.util.ResourceLeakDetector:76 -
-Dio.netty.noResourceLeakDetection: false
18:35:27,783 DEBUG
io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker:71 - [id:
0xc41b4658, /127.0.0.1:2410 => /127.0.0.1:8080] WS Version V13 server handshake
18:35:27,786 DEBUG
io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker:71 - WS
Version 13 Server Handshake key: 2WP6OSP2ldJdlDY5NPZxBw==. Response:
pzANkZagf3dP0kQ33Jq8676lnQI=.
18:35:27,789 WARN io.netty.channel.DefaultChannelPipeline:151 - An
exceptionCaught() event was fired, and it reached at the tail of the pipeline.
It usually means the last handler in the pipeline did not handle the exception.
java.lang.NullPointerException
at org.dna.mqtt.moquette.server.netty.NettyMQTTHandler.channelInactive(NettyMQTTHandler.java:81)
at io.netty.channel.DefaultChannelHandlerContext.invokeChannelInactive(DefaultChannelHandlerContext.java:232)
at io.netty.channel.DefaultChannelHandlerContext.fireChannelInactive(DefaultChannelHandlerContext.java:218)
at io.netty.channel.ChannelInboundHandlerAdapter.channelInactive(ChannelInboundHandlerAdapter.java:75)
at io.netty.channel.DefaultChannelHandlerContext.invokeChannelInactive(DefaultChannelHandlerContext.java:232)
at io.netty.channel.DefaultChannelHandlerContext.fireChannelInactive(DefaultChannelHandlerContext.java:218)
at io.netty.handler.codec.ByteToMessageDecoder.channelInactive(ByteToMessageDecoder.java:214)
at io.netty.channel.DefaultChannelHandlerContext.invokeChannelInactive(DefaultChannelHandlerContext.java:232)
at io.netty.channel.DefaultChannelHandlerContext.fireChannelInactive(DefaultChannelHandlerContext.java:218)
at io.netty.channel.ChannelInboundHandlerAdapter.channelInactive(ChannelInboundHandlerAdapter.java:75)
at io.netty.channel.DefaultChannelHandlerContext.invokeChannelInactive(DefaultChannelHandlerContext.java:232)
at io.netty.channel.DefaultChannelHandlerContext.fireChannelInactive(DefaultChannelHandlerContext.java:218)
at io.netty.channel.ChannelInboundHandlerAdapter.channelInactive(ChannelInboundHandlerAdapter.java:75)
at io.netty.channel.DefaultChannelHandlerContext.invokeChannelInactive(DefaultChannelHandlerContext.java:232)
at io.netty.channel.DefaultChannelHandlerContext.fireChannelInactive(DefaultChannelHandlerContext.java:218)
at io.netty.channel.ChannelInboundHandlerAdapter.channelInactive(ChannelInboundHandlerAdapter.java:75)
at io.netty.channel.DefaultChannelHandlerContext.invokeChannelInactive(DefaultChannelHandlerContext.java:232)
at io.netty.channel.DefaultChannelHandlerContext.fireChannelInactive(DefaultChannelHandlerContext.java:218)
at io.netty.channel.ChannelInboundHandlerAdapter.channelInactive(ChannelInboundHandlerAdapter.java:75)
at io.netty.handler.codec.http.HttpObjectAggregator.channelInactive(HttpObjectAggregator.java:219)
at io.netty.channel.DefaultChannelHandlerContext.invokeChannelInactive(DefaultChannelHandlerContext.java:232)
at io.netty.channel.DefaultChannelHandlerContext.fireChannelInactive(DefaultChannelHandlerContext.java:218)
at io.netty.handler.codec.ReplayingDecoder.channelInactive(ReplayingDecoder.java:347)
at io.netty.channel.DefaultChannelHandlerContext.invokeChannelInactive(DefaultChannelHandlerContext.java:232)
at io.netty.channel.DefaultChannelHandlerContext.fireChannelInactive(DefaultChannelHandlerContext.java:218)
at io.netty.channel.DefaultChannelPipeline.fireChannelInactive(DefaultChannelPipeline.java:767)
at io.netty.channel.AbstractChannel$AbstractUnsafe$5.run(AbstractChannel.java:558)
at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:354)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:348)
at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:101)
at java.lang.Thread.run(Thread.java:662)
18:35:28,098 DEBUG
io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker:71 - [id:
0x03e036d5, /127.0.0.1:2412 => /127.0.0.1:8080] WS Version V13 server handshake
18:35:28,099 DEBUG
io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker:71 - WS
Version 13 Server Handshake key: SCvw+oSgc9B2l6x3dMc0SA==. Response:
lF1UZN3/15mn05D1WxND16bjzsw=.
18:35:28,105 DEBUG
io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder:76 - Decoding
WebSocket Frame opCode=2
18:35:28,106 DEBUG
io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder:76 - Decoding
WebSocket Frame length=24
18:35:28,108 WARN io.netty.channel.DefaultChannelPipeline:151 - An
exceptionCaught() event was fired, and it reached at the tail of the pipeline.
It usually means the last handler in the pipeline did not handle the exception.
io.netty.handler.codec.DecoderException:
io.netty.util.IllegalReferenceCountException: refCnt: 0
at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:263)
at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:131)
at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:332)
at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:318)
at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103)
at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:332)
at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:318)
at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:103)
at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:332)
at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:318)
at io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler$1.channelRead(WebSocketServerProtocolHandler.java:133)
at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:332)
at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:318)
at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:173)
at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:332)
at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:318)
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:785)
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:100)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:478)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:447)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:341)
at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:101)
at java.lang.Thread.run(Thread.java:662)
Caused by: io.netty.util.IllegalReferenceCountException: refCnt: 0
at io.netty.buffer.AbstractByteBuf.ensureAccessible(AbstractByteBuf.java:1171)
at io.netty.buffer.AbstractByteBuf.checkIndex(AbstractByteBuf.java:1117)
at io.netty.buffer.AbstractByteBuf.getByte(AbstractByteBuf.java:330)
at io.netty.buffer.AbstractByteBuf.readByte(AbstractByteBuf.java:563)
at org.dna.mqtt.moquette.parser.netty.Utils.decodeRemainingLenght(Utils.java:75)
at org.dna.mqtt.moquette.parser.netty.Utils.checkHeaderAvailability(Utils.java:47)
at org.dna.mqtt.moquette.parser.netty.MQTTDecoder.decode(MQTTDecoder.java:55)
at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:232)
... 22 more
Original comment by alejo...@gmail.com
on 24 Nov 2014 at 11:41
Original issue reported on code.google.com by
radoslaw...@gmail.com
on 16 Mar 2014 at 9:15