Connected datagram channel (NettyDatagramServer)

116 views
Skip to first unread message

Ryan Crumley

unread,
Apr 9, 2014, 10:45:38 AM4/9/14
to reactor-...@googlegroups.com
I am trying to build a simple (udp) request/response server with NettyDatagramServer but I am running into trouble with the response. I understand datagram support is relatively new (and I am certainly new to using reactor, enjoying it a lot so far) so I'm think there is a 50/50 chance I am doing something wrong OR the framework doesn't support this use case yet. Here is a simplified snippet of my channel consumer:

private final class ChannelConsumer implements Consumer<NetChannel<IN, OUT>> {
@Override
public void accept(final NetChannel<IN, OUT> t) {
t.in().consume(new Consumer<IN>() {
@Override
public void accept(IN message) {
t.send(...);
}
});
}
}

When this is executed I get the following exception:

java.nio.channels.NotYetConnectedException: null
at sun.nio.ch.DatagramChannelImpl.write(DatagramChannelImpl.java:589)
at io.netty.channel.socket.nio.NioDatagramChannel.doWriteMessage(NioDatagramChannel.java:282)
at io.netty.channel.nio.AbstractNioMessageChannel.doWrite(AbstractNioMessageChannel.java:139)
at io.netty.channel.AbstractChannel$AbstractUnsafe.flush0(AbstractChannel.java:693)
at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.flush0(AbstractNioChannel.java:307)
at io.netty.channel.AbstractChannel$AbstractUnsafe.flush(AbstractChannel.java:662)
at io.netty.channel.DefaultChannelPipeline$HeadHandler.flush(DefaultChannelPipeline.java:1038)
at io.netty.channel.DefaultChannelHandlerContext.invokeFlush(DefaultChannelHandlerContext.java:677)
at io.netty.channel.DefaultChannelHandlerContext.flush(DefaultChannelHandlerContext.java:658)
at io.netty.channel.ChannelOutboundHandlerAdapter.flush(ChannelOutboundHandlerAdapter.java:115)
at io.netty.channel.DefaultChannelHandlerContext.invokeFlush(DefaultChannelHandlerContext.java:677)
at io.netty.channel.DefaultChannelHandlerContext.access$1600(DefaultChannelHandlerContext.java:29)
at io.netty.channel.DefaultChannelHandlerContext$WriteAndFlushTask.write(DefaultChannelHandlerContext.java:969)
at io.netty.channel.DefaultChannelHandlerContext$AbstractWriteTask.run(DefaultChannelHandlerContext.java:903)
at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:354)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:353)

What I would LIKE to do is send a datagram response to the same host and port the request came from... however I don't see how to do that. It appears I need a "connected" datagram channel or I need to specify the destination on the channel write. 

Does reactor support this or is there a customization point that I can extend to add it? Maybe override reactor.net.netty.udp.NettyDatagramServer.createChannel(C) and provide my own channel implementation?

Thanks in advance,

Ryan


Reply all
Reply to author
Forward
0 new messages